DDC-2590: Class inheritance - left join between child and parent entities #3320

doctrinebot opened this Issue Aug 6, 2013 · 1 comment

2 participants


Jira issue originally created by user darthcz:

The piece of code given under creates wrong sql to me.

Module is parent entity for BusinessModule entity. Category is joined with BusinessModule.

Module entity is only left joined to its child entity and that's the problem because it contains a field "name" used for filtering. So even if there is no module having the name, categories are still included.

I need the parent entity to be inner joined to child entity not left joined.

File doctrine2/lib/Doctrine/ORM/Query/SqlWalker.php line 353:

// If this is a joined association we must use left joins to preserve the correct result.
$sql .= isset($this->queryComponents[$dqlAlias]['relation']) ? ' LEFT ' : ' INNER ';
->from('Category', 'c')
->join('c.module', 'm', 'WITH', 'm.name = :moduleName')
->setParameter('moduleName', $moduleName);
SELECT c0*.category_id AS category_id0, c0_.title AS title1, c0_.h1 AS h12, c0*.alias AS alias3,
c0*.insertion_fee AS insertion_fee4, c0_.description AS description5, c0_.parent_category*id AS
parent*category_id6, c0_.module_id AS module*id7 
FROM category c0_ 
INNER JOIN business*module b1_ ON c0_.module_id = b1_.module*id 
LEFT JOIN module m2* ON b1_.module_id = m2_.module_id AND (m2*.name = ?)

Comment created by maryo:

I am experiencing the same issue. The workarround could be to use LEFT JOIN with IS NOT NULL condition... But it also doesnt work after this commit
d9c1782 (i had to revert to dev-master#13c1efb240dd0af25ad0abe230df98ec895892c7)

@beberlei beberlei was assigned by doctrinebot 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