Skip to content

Loading…

DDC-2250: Joining Associations in Single Inheritance Scheme #2950

Closed
doctrinebot opened this Issue · 3 comments

2 participants

@doctrinebot

Jira issue originally created by user johannes:

Let's assume the following class hierarchy:

AbstractComment
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.

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Issue was closed with resolution "Can't Fix"

@doctrinebot

Comment created by johannes:

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();
    }
}

$this->em->batchLoad($batch);
@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.