I have a ManyToMany relationship to an Entity (Fair <-> Hotels) with over 12.000 entries. When I'm using the DoctrineModule\Form\Element\ObjectMultiCheckbox in my form, the application runs out of memory. It seems like the ObjectMultiCheckbox loads every single entity which is saved in the database even though the Fair entity isn't assigned to any Hotel (and vice versa).
Here is the Fair entity with the Hotel relation:
/**
* @ORM\ManyToMany(targetEntity="Hotel", fetch="EXTRA_LAZY")
* @ORM\JoinTable(name="fair_core_has_hotel", joinColumns={@ORM\JoinColumn(name="fair_core_id", referencedColumnName="id")})
*/
private $hotel;
And here is the ObjectMultiCheckbox in the FairForm:
$this->add(array(
'name' => 'hotel',
'type' => 'DoctrineModule\Form\Element\ObjectMultiCheckbox',
'options' => array(
'entity' => 'hotel',
'unchecked_value' => '',
'object_manager' => $em,
'target_class' => 'Customer\Entity\Hotel',
'label_generator' => function($targetEntity) {
return "".$targetEntity->getLabel();
},
'attributes' => array('required' => false),
),
));
Already tried to change the fetch-mode to EXTRA_LAZY but it doesn't make any difference. Also the relation is unidirectional, the Hotel entity doesn't know anything about the Fair entity.
Is there any solution? Or have I done something wrong?