I have 2 entities: User
and Metadata
. They have a bi-directional one-to-many relationship (a user can have many metadata records).
In a context decorator I'm using for flagception, I query the user and some of the user's relationships that may be needed using DQL:
$dql = "
SELECT user
FROM
\meQ\Entity\User user
JOIN user.profile profile
JOIN profile.client client
JOIN user.metadata metadata
WHERE user.uid = :user_id
";
$this->user = $em->createQuery($dql)
->setParameter('user_id', $session_user->getId())
->useQueryCache(true)
->getOneOrNullResult();
// for debug
dump($this->user);
exit();
This query returns the user, complete with the user->profile
and user->profile->client
fields populated correctly. However, it does not have its metadata field populated.
The user in question has 18 metadata records, but performing dump($this->user)
shows me an empty ArrayCollection:
Here is my Doctrine mapping for this relationship:
AppBundle\Entity\User:
# ...
oneToMany:
metadata:
fetch: EXTRA_LAZY
targetEntity: AppBundle\Entity\UserMetadata
mappedBy: user
cascade: [all]
orphanRemoval: true
indexBy: name
and the other side of the relationship:
AppBundle\Entity\UserMetadata:
# ...
manyToOne:
user:
targetEntity: AppBundle\Entity\User
inversedBy: metadata
joinColumn:
name: user_id
referencedColumnName: uid
Does this not work because User isn't the owning side?