Doctrine retrieves EAGER in many ways

Using Symfony 3.2 and Doctrine 2.5, I am having a hard time figuring out how to extract "EAGER" to work in many ways and in many ways.

Let's assume we have two objects, 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 just call

 $users = $this->getDoctrine()->getRepository('CoreBundle:User')->findAll();

      

I only want to see 1 query in the User table with a join in the site table, but I am getting N + 1 queries. I also ran several tests with many associations and got the same result.

I know I can do this myself using DQL, but I want to understand how "EAGER" works.

What is the expected behavior with EAGER sampling for many-to-many and many-to-one associations?

+3


source to share





All Articles