Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't update entity that has a composite FK as part of its PK #1658

Closed
erik-induro opened this issue Apr 7, 2021 · 0 comments
Closed

Can't update entity that has a composite FK as part of its PK #1658

erik-induro opened this issue Apr 7, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@erik-induro
Copy link

erik-induro commented Apr 7, 2021

Describe the bug
I have an entity whose primary key includes a composite foreign key. I can't update it. The generated sql appears to be wrong. This is a pretty common scenario for me since I am using partitioned tables.

Stack trace
N/A - there is no error but here is the generated (formatted) query:

update "site"
set "name" = 'Site 2'
where ("program_id", "program_organization_id") in (
  select "e0"."id", "e0"."program_id"
  from (
    select distinct "e0"."id", "e0"."program_id"
    from "site" as "e0"
    left join "program" as "e1"
      on "e0"."program_id" = "e1"."id"
      and "e0"."program_organization_id" = "e1"."organization_id"
    where "e0"."id" = '7007a128-4cc0-4177-b754-0cda0927368d'
      and "e1"."id" = 'cc455d1f-f4c7-4b57-b833-e6ca88239b61'
      and "e1"."organization_id" = 'e3dca7ae-6389-49dc-931d-419716828a79'
  ) as "e0"
)

As you can see, the where is looking for "program_id", "program_organization_id" but the inner select returns "site_id", "program_id" (I translated them). So it never matches and updates 0 rows.

To Reproduce
I updated my previous example here with a new test:
https://github.com/erik-induro/mikro-orm-fk

Expected behavior
The entity should be updated.

Additional context
N/A

Versions

Dependency Version
node 14.15.3
typescript 4.2.3
mikro-orm 4.5.2
@mikro-orm/postgresql 4.5.2
@B4nan B4nan added the bug Something isn't working label Apr 7, 2021
@B4nan B4nan closed this as completed in b1420a6 Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants