[DDC-2250] Joining Associations in Single Inheritance Scheme Created: 20/Jan/13  Updated: 20/Jan/13  Resolved: 20/Jan/13

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Johannes Schmitt Assignee: Benjamin Eberlei
Resolution: Can't Fix Votes: 0
Labels: None


Let's assume the following class hierarchy:

SpecialComment extends AbstractComment
    private $specialAssociation;
RegularComment extends RegularComment

Now, I'd like to write a query such as:

SELECT c, a FROM AbstractComment c LEFT JOIN c.specialAssociation a

The idea is to preload the association when selecting all comments. Now, that association is only present on a sub-class of the queried class, but since it is a single table inheritance, Doctrine should be able to join it for those entities where it is present.

At the moment unfortunately, Doctrine shows an error that the association does not exist on the AbstractComment class. Also, there is no real alternative to this except moving the collection to the base class even if it does not belong there.

Comment by Benjamin Eberlei [ 20/Jan/13 ]

DQL has strict typing with regard to inheritance, this type of query is not possible.

Comment by Johannes Schmitt [ 20/Jan/13 ]

A too bad. I guess the code around inheritance is already quite complex that it does not make sense to add an exception for this case.

Do you think it would somehow (maybe manually) be possible to load collections in a batch operation? For example, something like this:

$batch = array();
foreach ($comments as $comment) {
    if ($comment instanceof SpecialComment) {
        $batch[] = $comment->getSpecialAssociation();

Generated at Sat Oct 10 12:15:44 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.