[Answered] ManyToMany relation set fetch EAGER on owner side

0 votes
asked Jan 14, 2016 in Solved by soyuka (210 points)
recategorized May 28, 2016 by ludek.vodicka

Hi,

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

commented Jan 14, 2016 by ludek.vodicka Skipper developer (140,450 points)

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

commented Jan 14, 2016 by soyuka (210 points)

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;
commented Jan 14, 2016 by ludek.vodicka Skipper developer (140,450 points)

Thanks, we will check it

1 Answer

+1 vote
answered Jan 18, 2016 by ludek.vodicka Skipper developer (140,450 points)
selected Jan 18, 2016 by soyuka
 
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?

commented Jan 18, 2016 by soyuka (210 points)

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

commented Jan 18, 2016 by ludek.vodicka Skipper developer (140,450 points)

no problem. Have a nice day

...