1

I have a rather big number of classes related to each other via various relations (OneToOne, OneToMany, ManyToOne as well as Class- and Joined Inheritance which in turn again have multiple relations.

When I want to select all of a parent class via a simple ->findAll(), I get around 10 extra queries per Entity. I can reduce this number by a limited extend by unsing the a QueryBuilder with ->leftJoin() and ->addSelect(). Some relations do not join because reasons. Still, it gets a pretty nasty long list of addSelect()s. Is there a way to join and select all relations automatically?

2 Answers2

1

The automatical join can be achieved by setting the fetch-mode of the associations to eager (e.g. on ManyToOne:

/**
 * @ManyToOne(targetEntity="Cart", cascade={"all"}, fetch="EAGER")
 */

, see the docs)

To set the fetch mode programatically, refer to another StackOverflow question.

0

Try using "JoinTable" or "JoinColumn"

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#jointable

Cesur APAYDIN
  • 806
  • 3
  • 11
  • 24