Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2590

Class inheritance - left join between child and parent entities

    Details

    • Type: Bug Bug
    • Status: Awaiting Feedback
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.3.1, 2.3.2, 2.3.3, 2.3.4
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All

      Description

      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 ';
      
      $qb->select('c')
      ->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 = ?)
      

        Activity

        Hide
        Marek Štípek added a comment - - edited

        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
        https://github.com/doctrine/doctrine2/commit/d9c1782a4f6d46f66e9deb2c375830f9192d4482 (i had to revert to dev-master#13c1efb240dd0af25ad0abe230df98ec895892c7)

        Show
        Marek Štípek added a comment - - edited 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 https://github.com/doctrine/doctrine2/commit/d9c1782a4f6d46f66e9deb2c375830f9192d4482 (i had to revert to dev-master#13c1efb240dd0af25ad0abe230df98ec895892c7)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Tomáš Ďuračka
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: