I'm using Symfony2 with Doctrine2 (latest versions) and have this relation defined:
/**
* @ORM\OneToMany(targetEntity="Field", mappedBy="event", fetch="EAGER")
* @ORM\OrderBy({"name" = "ASC"})
*/
protected $fields;
The other side of the relation is defined as:
/**
* @ORM\ManyToOne(targetEntity="Event", inversedBy="fields", fetch="EAGER")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
protected $event;
When doing a "fetchOnyById", Doctrine runs 2 queries. 1 to fetch the object itself and 1 for the related fields. I would expect this to be a join, but it isn't.
When done in the controller, I pass my object to twig. There I retrieve the fields again as a property of the object. This causes another query to be run to retrieve the fields again.
Clearly I'm doing something wrong, as I would expect only 1 query to be run and 3 are actually run.