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

Discriminator column is not considered correctly for class table inheritance


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


      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)?



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


            • Created: