Home Documentation Download Pricing Buy Now

[Answered] ManyToMany relation set fetch EAGER on owner side

0 votes

Hi,

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

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

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?

answered Jan 18, 2016 by ludek.vodicka Skipper developer (140,530 points)
selected Jan 18, 2016 by soyuka

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

no problem. Have a nice day

...