-
-
Notifications
You must be signed in to change notification settings - Fork 499
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
LoadStrategy.JOINED with pagination/populateWhere weird behavior #3871
Comments
Maybe related to #2985 ? |
Both the In any case, if you can propose ways for how the queries can work for the weird cases, it would help a lot. With select-in strategy its quite easy to reason about those things, but for the joined strategy, I am often not sure how to do it. |
Well, correct me if I'm wrong, but in postgres (idk about other drivers) you can left join with an 'and' operator like this: select * from "user"
left join "pet" on "pet"."user_id" = "pet"."id" and "pet"."name" = 'y' notice the bare-bones query: select * from "user"
left join "pet" on "pet"."user_id" = "pet"."id" All the pets are populated as they should be the query with select * from "user"
left join "pet" on "pet"."user_id" = "pet"."id"
and "pet"."name" = '1931dasda' None of the pets are populated etc.. |
Well, I believe with pagination it's much more complicated, but I haven't really checked the exact repro yet. Btw I would appreciate less screenshots and more code examples, this is quite a mess :] |
Yeah, pagination with joins is tricky But let's take one example query generated by mikro orm select
"u0"."id",
"p1"."id" as "p1__id",
"p1"."name" as "p1__name",
"p1"."user_id" as "p1__user_id",
"p1"."action_id" as "p1__action_id"
from
"user" as "u0"
left join "pet" as "p1" on "u0"."id" = "p1"."user_id"
where
"u0"."id" in (
select
"u0"."id"
from
(
select
"u0"."id"
from
"user" as "u0"
left join "pet" as "p1" on "u0"."id" = "p1"."user_id"
group by
"u0"."id"
limit
30
) as "u0"
)
and "p1"."name" = 'yoyo' I took this from my repro 4 example It returns only 1 record, user with the pet named Now if I move the select
"u0"."id",
"p1"."id" as "p1__id",
"p1"."name" as "p1__name",
"p1"."user_id" as "p1__user_id",
"p1"."action_id" as "p1__action_id"
from
"user" as "u0"
left join "pet" as "p1" on "u0"."id" = "p1"."user_id"
and "p1"."name" = 'yoyo'
where
"u0"."id" in (
select
"u0"."id"
from
(
select
"u0"."id"
from
"user" as "u0"
left join "pet" as "p1" on "u0"."id" = "p1"."user_id"
group by
"u0"."id"
limit
30
) as "u0"
) It returns 30 users, and only 1 has the pets populated, this should be the expected behavior? (same as SELECT_IN) |
Yes, the select-in behavior is indeed the expected one. |
Implemented in v6. |
Closes #3871 Signed-off-by: Martin Adámek <banan23@gmail.com>
When using joined strategy, the `populateWhere` condition is now applied to the joins via `on` conditions instead of using a `where` condition. This aligns how the two loading strategies work, as the `populateWhere` will affect only what gets joined, but not the root entity query. Closes #3871 Signed-off-by: Martin Adámek <banan23@gmail.com>
Describe the bug
It seems that when using the JOINED strategy the populateWhere gets ignored in queries without pagination. But when you try to paginate with the JOINED strategy weird results are returned, more detailed info in the repo that I created.
Everything works as expected with the SELECT_IN strategy
To Reproduce
I have created a repo https://github.com/Tronikelis/mikro-orm-issue-1
Expected behavior
I would expect that there would be no difference between these 2 strategies: JOINED/SELECT_IN
Versions
Happy holidays btw 👍
The text was updated successfully, but these errors were encountered: