Details
-
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: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)?
Can you provide more information on your usecase and where this leads to wrong results? Unless you're altering the discriminator column values yourself this should be no problem?