0 votes

Hi,

I can't find a way to set "fetch EAGER" on the owning side of a ManyToMany relation.

in Solved by (190 points)
recategorized by

Can you please attach link to documentation where is this setting described? Thanks

http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#manytomany

For example:

/**
 * @ORM\ManyToMany(targetEntity="ProductBundle\Entity\QualityLabel", fetch="EAGER")
 * @ORM\JoinTable(
 *     name="PToQualityLabel",
 *     joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")},
 *     inverseJoinColumns={@ORM\JoinColumn(name="qualitylabel_id", referencedColumnName="id")}
 * )
 */
private $qualityLabels;

Thanks, we will check it

1 Answer

+1 vote
Best answer

Hi,

we tried it here and it seems that everything works as expected. You have to choose one of two m-n directions and set "fetch" property:

enter image description here

after that exported schema will be:

<?php
use Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity
 */
class E2
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\ManyToMany(targetEntity="SampleEntity", inversedBy="e2", fetch="EAGER")
     * @ORM\JoinTable(
     *     name="mn",
     *     joinColumns={@ORM\JoinColumn(name="e2_id", referencedColumnName="id", nullable=false)},
     *     inverseJoinColumns={@ORM\JoinColumn(name="sample_entity_id", referencedColumnName="id", nullable=false)}
     * )
     */
    private $sampleEntity;
}

Is this what you need?

by Skipper developer (136k points)
selected by

Indeed, can't see how I missed it, thanks.

no problem. Have a nice day