mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-2574: Add posibility to fetch subclass associations in a polymorphic query #3227
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jul 27, 2013).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user nbottarini:
Suppose you have a parent class A and a subclass B that has an association with class C.
If you want to make a polymorphic query on all instances of class A the relation on class C in the subclass B always returns a proxy.
There's not posibility to use a left join with class C to fetch that association. This causes a N+1 SELECT performance problem.
@doctrinebot commented on GitHub (Jul 27, 2013):
Comment created by @ocramius:
This is a known/wanted limitation. Fetch-joining on associations of subclasses is not supported anyway, since from a DQL perspective, these associations don't exist at all. It's a very old won't fix: see DDC-16
@doctrinebot commented on GitHub (Jul 27, 2013):
Comment created by @ocramius:
Related to DDC-16
@doctrinebot commented on GitHub (Jul 27, 2013):
Issue was closed with resolution "Won't Fix"
@doctrinebot commented on GitHub (Jul 27, 2013):
Comment created by nbottarini:
Hi Marco, thanks for the fast response!
Suppose you have a base Notification class and then a subclass for each type of concrete notification (UserFollowNotification, ProductAddedNotification, etc etc). You can't show the user's notifications with each notification detail without incurring in a n+1 performance problem. How do you deal with this kind of situations in doctrine?. In Nhibernate, for example, you can choose that an association must always be fetched at mapping level or at query level (with DataLoading options).
How do you handle this situations in doctrine?
Thank you very much.
@doctrinebot commented on GitHub (Jul 27, 2013):
Comment created by @ocramius:
[~nbottarini] assuming that you want to work only on a particular subclass, you may want to refresh a set of objects by building a specific DQL query.
First, retrieve all your records that contain the said collection. Then create following query:
SELECT f, b FROM Foo f LEFT JOIN f.bar b WHERE f.id IN (:foos)You can then run this query against the objects you fetched:
$refreshedFoos = $query->setParameter('foos', $fetchedObjects)->setHint(\Doctrine\ORM\Query::HINT_REFRESH, true)->getResult();This should reduce the overhead greatly.
@doctrinebot commented on GitHub (Jul 27, 2013):
Comment created by nbottarini:
Thank you very much Marco!