Using Symfony 3.2 and Doctrine 2.5, I have trouble to understand how fetch "EAGER" should work in many-to-many and many-to-one relationship.
Lets say we have two entities, User and Site, and a many-to-many association:
class User
{
/**
* @ORM\ManyToMany(targetEntity="Site", inversedBy="users", fetch="EAGER")
* @ORM\JoinTable(name="user_site")
*/
private $sites;
}
class Site
{
/**
* @ORM\ManyToMany(targetEntity="User", mappedBy="sites")
*/
private $users;
}
In my controller, i simply call
$users = $this->getDoctrine()->getRepository('CoreBundle:User')->findAll();
I want to see only 1 query on the User table with a join on the Site table, but i get N+1 queries. I have also did some tests with many-to-one associations and get the same result.
I know that i can do the join by myself using DQL, but i want to understand how fetch "EAGER" does work.
What is the expected behavior with fetch "EAGER" on many-to-many and many-to-one associations ?