Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2225

Discriminator column is not considered correctly for class table inheritance

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: Git Master
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Imagine having a class table inheritance for Employee and Person:

      class Person {} => is mapped to table "person"
      class Employee extends Person {} is mapped to table "person_employee"

      When selecting "SELECT e FROM Employee" the SqlWalker will not generate a WHERE condition for a correct discriminator column value (e.g. "employee"). The ORM seems to trust on the generated INNER JOIN (person.id = person_employee.id).

      Of course the table person_employee should only contain rows for Employee ojects. But if you have a discriminator value "person" for a row matching an Employee row, the repository will return a Person object although we selected from Employee.

      A simple fix is to add the correct DQL expression:
      SELECT e FROM Employee WHERE e INSTANCE OF Employee

      Is there any reason, why the discriminator column is only considered for single table inheritance explicitly (see https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Query/SqlWalker.php#L426)?

        Activity

        Per Bernhardt created issue -
        Alexander made changes -
        Field Original Value New Value
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]
        Per Bernhardt made changes -
        Status Awaiting Feedback [ 10000 ] In Progress [ 3 ]
        Per Bernhardt made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Won't Fix [ 2 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Per Bernhardt
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: