Eager loading for nested entities #11138
Unanswered
lewbor
asked this question in
Support Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Eager loading now works for single entity and collections. But if we have a entity classes like this:
class A {
#[OneToMany(mappedBy: 'source', targetEntity: B::class]
private Collection $bCollection;
}
class B {
private A $source;
#[ManyToOne(targetEntity: C::class)]
private C $c
}
class C {
}
`
if we want to fetch A -> B -> C all entities using Query::setFetchMode() method it does not work. For example this code:
$em->createQueryBuilder()
->select('entity')
->from(A::class,'entity')
->getQuery()
->setFetchMode(A::class, 'bCollection', ClassMetadataInfo::FETCH_EAGER)
->setFetchMode(B::class, 'c', ClassMetadataInfo::FETCH_EAGER)
->getResult()
will correctly load collections in A entities, but $c field in B entity will be a not initialized proxy.
Is there a correct way to do this multi-step hydration (not using joins or partial syntax)?
Beta Was this translation helpful? Give feedback.
All reactions