Description

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

Alexander
added a comment - 09/Feb/13 11:36 PM 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?

Marco Pivetta
added a comment - 09/Feb/13 11:39 PM JTI assumes that your rows in table `person_employee` are part of instances of `Employee`.
If you manually altered the discriminator column, that cannot be helped, since the ORM does not support casting.

Yes, the discriminator column is "manually" altered by our CMS. In other words, our CMS does not care to delete rows in any subtable, it only changes the discriminator column. So a valid solution for this situation is to change that, of course.

But why does the ORM check the discriminator column only for single table inheritance? In other words: Why do we need to have a discriminator column for class table inheritance, if the ORM does not rely on it?

Per Bernhardt
added a comment - 12/Feb/13 9:39 AM Yes, the discriminator column is "manually" altered by our CMS. In other words, our CMS does not care to delete rows in any subtable, it only changes the discriminator column. So a valid solution for this situation is to change that, of course.
But why does the ORM check the discriminator column only for single table inheritance? In other words: Why do we need to have a discriminator column for class table inheritance, if the ORM does not rely on it?

Per Bernhardt
added a comment - 12/Feb/13 9:50 AM Do you think it would break things when checking the discriminator column for class table inheritance in https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Query/SqlWalker.php#L426?