mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Accessing Many-To-Many Relation in child entity through parent using CTI #6537
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 @InjustFr on GitHub (Sep 7, 2020).
Hi,
I'm trying to load ManyToMany associations on child entities using the parent entity. Here is an example to try to make this clearer:
I have a parent abstract Entity. Let's call it Animal. Then I have two entities inheriting Animal called Dog and Cat. Dog has a ManyToMany relation with DogHouse and Cat a ManyToMany relation with LitterBox. The inheritance type is a CTI
Now when I load all the Animal I want to fetch at the same time DogHouse and LitterBox to avoid several queries when accessing those entities
I've tried a bunch of ways and it either throws errors as DogHouse and LitterBox do not have a relation with Animal or the hydration breaks and instead of a collection of Animal entities I end up with a collection of Animal, DogHouse and LitterBox
I've searched for ages on the Web and haven't found my answer, sadly
Here are examples of the requests I tried :
I don't know if this is possible through DQL/QueryBuilder
Thanks in advance for your help
@beberlei commented on GitHub (Sep 13, 2020):
This is not possible, because inheritance rules are enforced in DQL as they would be in PHP. You can convert it to a native SQL query or rethink your use of inheritance, it looks like it might not be a good fit.