DDC-2634: Adding a WITH clause on leftJoin places the JOIN ... AND in the wrong place combined with inheritance mapping #3368

Closed
doctrinebot opened this Issue Aug 27, 2013 · 4 comments

2 participants

@doctrinebot

Jira issue originally created by user brammm:

I implement following querybuilder:
$qb = $this->createQueryBuilder('it')
->select('it, i')
->leftJoin('it.items', 'i', 'WITH', 'i.archived = false')
->orderBy('it.position', 'ASC')
;

Note: the result is the same with
return $this->getEntityManager()
->createQuery('
SELECT it, i FROM AcmeDemoBundle:ItemType it
LEFT JOIN it.items i WITH i.archived = 0
ORDER BY it.position ASC')
->getResult();

The Item entity has inheritance mapping to (at the moment) one subclass, ObjectItem. The archived property is on the Item class (not ObjectItem).

The generated query is
SELECT
...
FROM
itemtype i0
LEFT JOIN item i1* ON i0_.id = i1_.item_typeid
LEFT JOIN object
item o2_ ON i1_.id = o2*.id
AND (i1_.archived = 0)
ORDER BY
i0_.position ASC

This causes issues and unexpected in MySQL and a wrong set of results. The generated query should be
SELECT
...
FROM
itemtype i0
LEFT JOIN item i1* ON i0_.id = i1_.item_typeid
AND (i1_.archived = 0)
LEFT JOIN object
item o2_ ON i1_.id = o2*.id
ORDER BY
i0_.position ASC

@doctrinebot

Comment created by @beberlei:

Can you check this again with 2.4? I think we have fixed this bug in 2.4

@doctrinebot

Comment created by brammm:

Saw you (Benjamin) walking around phpbnl14 and remembered this. Just reproduced it in 2.4 and works now. So fixed, can be closed.

@doctrinebot

Comment created by brammm:

reproduced in 2.4, works now.

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.4.1 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment