Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-2235

Single table inheritance discriminator in WHERE when using arbitrary join syntax

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      The condition on the discriminator column is placed in the WHERE clause when using arbitrary join syntax, which renders LEFT JOINs useless.

      Given these classes:
      A - no inheritance
      B1 - abstract, root of a hierarchy, discriminator column is named 'type'
      I setup a query builder like this:

      $qb->select('a.id AS idA, b.id AS idB')
          ->from('\Entity\A', 'a')
          ->leftJoin('\Entity\B1', 'b', \Doctrine\ORM\Query\Expr\Join::WITH, 'a.something=b.something');
      And the SQL Doctrine generates is something like this:
      SELECT a.id, b.id FROM a LEFT JOIN b ON (a.something=b.something) WHERE b.type IN ('1', '2', '3')
      

      The problems is that the WHERE condition makes the left join useless.

      The condition on the discriminator column should be placed in the JOIN clause to avoid the problem.

        Issue Links

          Activity

          Show
          ocramius Marco Pivetta added a comment - Fixed at https://github.com/doctrine/doctrine2/commit/605c32dbb384e25117625a7cb4db4e7319a16bae ( https://github.com/doctrine/doctrine2/pull/758 )
          Hide
          beberlei Benjamin Eberlei added a comment -

          merged into 2.4

          Show
          beberlei Benjamin Eberlei added a comment - merged into 2.4
          Hide
          doctrinebot Doctrine Bot added a comment -

          A related Github Pull-Request [GH-656] was closed:
          https://github.com/doctrine/dbal/pull/656

          Show
          doctrinebot Doctrine Bot added a comment - A related Github Pull-Request [GH-656] was closed: https://github.com/doctrine/dbal/pull/656
          Hide
          doctrinebot Doctrine Bot added a comment -

          A related Github Pull-Request [GH-708] was closed:
          https://github.com/doctrine/dbal/pull/708

          Show
          doctrinebot Doctrine Bot added a comment - A related Github Pull-Request [GH-708] was closed: https://github.com/doctrine/dbal/pull/708
          Hide
          doctrinebot Doctrine Bot added a comment -

          A related Github Pull-Request [GH-708] was assigned:
          https://github.com/doctrine/dbal/pull/708

          Show
          doctrinebot Doctrine Bot added a comment - A related Github Pull-Request [GH-708] was assigned: https://github.com/doctrine/dbal/pull/708

            People

            • Assignee:
              guilhermeblanco Guilherme Blanco
              Reporter:
              jay.eff Jordi Forns
            • Votes:
              6 Vote for this issue
              Watchers:
              12 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: