When I iterate over users of one group (group#users and it's a ManyToOne relationship) to display the users emails, I get this error Entity of type 'AppBundle\Entity\User' for IDs id(155) was not found
. However, when I display the user for which the exception is raised I see this:
// In my controller
dump($groups[0]->getUser());
// Output
User {#761 ▼
+__isInitialized__: false
#id: 155
#email: null
#firstName: null
#lastName: null
#roles: null
…2
}
Besides, this user (whose id equals 155) does exist in my database.
UPDATE 1
public function getByCriteria(array $criteria)
{
$qb = $this->createQueryBuilder('g');
// ....
return $qb
->getQuery()
// This does NOT change anything ?? Isn't this supposed to load related user??
// http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#temporarily-change-fetch-mode-in-dql
->setFetchMode('class_namespace', 'user', ClassMetadata::FETCH_EAGER)
->getResult();
}