mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Combination of ManyToMany relation and LEFT JOIN "WITH" produces extra rows #5420
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Erikvv on GitHub (Feb 17, 2017).
produces the following SQL:
The first left join leads to extra rows due to activities which do not match the WITH clause.
Note that it works correctly when using INNER JOIN or a OneToMany relationship.
Maybe this can be solved by moving the condition from the second to the first LEFT JOIN like so:
@lcobucci commented on GitHub (Feb 20, 2017):
@Erikvv I'm not sure but I think you can use a
MEMBER OFinstead of a join to achieve what you want and the ORM will generate the proper query (e.g.:$qb->andWhere(':activity MEMBER OF person. activities')->setParameter('activity', 3);).@Erikvv commented on GitHub (Feb 21, 2017):
It would not be the same behavior. If you left join to one activity with id 2 and then filter only id 3 you lose the person record entirely.
(it's not that I can't think of a solution it's just that the current behavior is unintuitive)
@lcobucci commented on GitHub (Feb 21, 2017):
@Erikvv sure, that should behave the same way as the
inner joinbut without requiring the join.We do need a testing case though, could you please create something to reproduce that unexpected behaviour (something like
e4704beaf9/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5562Test.php)?@Erikvv commented on GitHub (Feb 22, 2017):
I'll write a test case, but I'm not sure I can make a patch, I am not familiar with parsers.