I have to following setup: A parent class
/**
* @ORM\Entity()
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
*/
abstract class DataCategory
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
//...
}
and several derived classes which hold references to the parent (only showing here one)
/**
* @ORM\Entity
*/
class MultiCompoundDataCategory extends DataCategory
{
/**
* @ORM\ManyToMany(targetEntity="DataCategory", fetch="EXTRA_LAZY")
* @ORM\JoinTable(name="multi_compound_data_category_data_category",
* joinColumns={@ORM\JoinColumn(name="multi_compound_data_category", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="data_category", referencedColumnName="id")})
*/
public $summands;
public function __construct()
{
$this->summands = new ArrayCollection();
}
}
Now when loading all MultiCompoundDataCategories via
$this->getDoctrine()->getRepository(MultiCompoundDataCategory::class)->findAll()
, not only one select on MultiCompoundDataCategories is issued (with a join on the ManyToMany-table). Instead I get one main query, followed by one query for each summand, each with a big fat sequence LEFT JOIN
(also the docs contain a warning about this problem, I am massively referencing non-leaf nodes of the inheritance tree).
BTW: Wouldn't LAZY
fetching already suffice to avoid loading the ManyToMany ?
From this comment, I assume the problem is that my child entities refencence the parent one. How can I circumvent this? MappedSuperclass?