You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
EDIT: @Filter is not causing this, see bottom of issue.
Using $or statements in pre-defined filter criteria attached to entities (@Filter), while using $or statements in the conditions object of the find method, causes certain filters/conditions to be left out of the find method.
I found that wrapping the $or statement in the conditions object in an $and statement fixes the issue. But this shouldn't be necessary.
select"e0".*from"user"as"e0"where ("e0"."first_name"='name'or"e0"."last_name"='name') and ("e0"."age"=18or"e0"."age"=21)
select"e0".*from"membership"as"e0"left join"user"as"e1"on"e0"."user_id"="e1"."id"where ("e0"."role"='admin'or"e0"."role"='moderator') and ("e1"."first_name"='name'or"e1"."last_name"='name')
Expected behavior
All $or statements in find conditions and in @Filter statements should be conjugated in one query, without having to wrap one in an explicit $and statement.
Edit:
The issue isn't in @Filter , but in the FilterQuery conditions object when it's given multiple $or statements.
select"e0".*from"membership"as"e0"left join"user"as"e1"on"e0"."user_id"="e1"."id"where ("e0"."role"='admin'or"e0"."role"='moderator') and ("e1"."first_name"='John'or"e1"."last_name"='Doe')
The text was updated successfully, but these errors were encountered:
NicolasDesmedt
changed the title
@Filter with $or statements builds incorrect query
Find with multiple $or statements builds incorrect query
May 10, 2021
The issue is indeed with filters and how they are merged, with few more "child problems", I already got it fixed, but it had a lot of side effects, still having some tests failing.
Your edit might be another problem. With the filters the conditions were merged, but the values if both sides are defined were not merged, but rather replaced, so merging $or conditions were not working at all, the latest one was already there, the rest were overriden.
Previously multiple filter conditions were object-merged, which could result
in ignoring the left-hand side conds sometimes, especially when it comes to
merging group operators. This changes the way we merge them, so instead of
object-merging, we now craft an `$and` query with all the child conditions.
As part of this it was also needed to adjust how child conditions are being
created for select-in population. It should now also work with group operators,
which were previously ignored.
Closes#1776
Describe the bug
EDIT: @Filter is not causing this, see bottom of issue.
Using $or statements in pre-defined filter criteria attached to entities (@Filter), while using $or statements in the conditions object of the find method, causes certain filters/conditions to be left out of the find method.
I found that wrapping the $or statement in the conditions object in an $and statement fixes the issue. But this shouldn't be necessary.
Given simplified entities
Following find methods result in incorrect queries:
While wrapping a single $or statement in an unnecessary $and produces the wanted queries:
To Reproduce
I published a small repo with above test cases as a proof-of-concept.
https://github.com/NicolasDesmedt/mikro-orm-filter-issue
Expected behavior
All $or statements in find conditions and in @Filter statements should be conjugated in one query, without having to wrap one in an explicit $and statement.
Edit:
The issue isn't in @Filter , but in the FilterQuery conditions object when it's given multiple $or statements.
Doesn't work:
Works:
The text was updated successfully, but these errors were encountered: