Liaison entre deux entités en symfony2

Signaler
-
Bonjour,

J'ai un soucis en symfony2, j'utilise sonata bundle et quand j'essai de créer un nouveau partenaire, j'ai cette exception :

The current field `medias` is not linked to an admin. Please create one for the target entity : `AppBundle\Entity\Media\PartnerMedia`

Je ne comprends pas ce qui se passe. J'ai tout d'abord générer une entité partenaire et une autre partenaireMedia car un partenaire peut avoir plusieurs médias. Du coup, voici le contenu de mon entité partenaire :

class Partner extends SortableTranslatableEntity implements TranslatableInterface
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
    /**
     * @var string
     *
     * @ORM\Column(name="libelle", type="string", length=60)
     * @Gedmo\Translatable
     */
    private $libelle;
 
    /**
     * @var string
     *
     * @ORM\Column(name="mea", type="boolean")
     */
    private $mea;
 
 
    /**
     * @ORM\OneToMany(targetEntity="\AppBundle\Entity\Media\PartnerMedia", mappedBy="partner", cascade={"persist"}, orphanRemoval=true)
     * @ORM\OrderBy({"position" = "ASC"})
     */
    private $medias;
 
    /**
     * @ORM\Column(type="string", name="url", nullable=true)
     * @Gedmo\Translatable
     */
    private $url;
 
    /**
     * @ORM\ManyToOne(targetEntity="\AppBundle\Entity\CMS\Block", inversedBy="block")
     */
    private $block;
 
 
    public function __construct()
    {
        $this->medias = new ArrayCollection();
    }
 
    public function setTranslatableLocale($locale)
    {
        $this->locale = $locale;
    }
 
    public function getContextName()
    {
        return 'partner';
    }
 
    public function __toString()
    {
        return $this->getId() ? (string) $this->getLibelle() : '-';
    }
 
    public function firstPhoto()
    {
        if ($this->getMedias() && $this->getMedias()->count()) {
            return $this->getMedias()->first()->getMedia();
        }
    }
 
    public function getId()
    {
        return $this->id;
    }
 
    public function getLibelle()
    {
        return $this->libelle;
    }
 
    /**
     * Add medias.
     *
     * @param PartnerMedia $media
     *
     * @return PartnerMedia
     */
    public function addMedias(PartnerMedia $media)
    {
        $media->setPartner($this);
        $this->medias[] = $media;
 
        return $this;
    }
 
    /**
     * Remove medias.
     *
     * @param PartnerMedia $media
     */
    public function removeMedia(PartnerMedia $media)
    {
        $this->medias->removeElement($media);
    }
 
    public function getMedias()
    {
        return $this->medias;
    }
 
    public function getUrl()
    {
        return $this->url;
    }
 
    /**
     * Get page.
     *
     * @return \AppBundle\Entity\CMS\Block
     */
    public function getBlock()
    {
        return $this->block;
    }
 
    public function setId($id)
    {
        $this->id = $id;
    }
 
    public function setLibelle($libelle)
    {
        $this->libelle = $libelle;
    }
 
    public function setUrl($url)
    {
        $this->url = $url;
    }
 
    /**
     * Set page.
     *
     * @param \AppBundle\Entity\CMS\Block $block
     * @return Partner
     */
    public function setBlock(Block $block = null)
    {
        $this->block = $block;
 
        return $this;
    }
 
 
    /**
     * Set mea
     *
     * @param boolean $mea
     * @return Partner
     */
    public function setMea($mea)
    {
        $this->mea = $mea;
 
        return $this;
    }
 
    /**
     * Get mea
     *
     * @return boolean
     */
    public function getMea()
    {
        return $this->mea;
    }
 
    /**
     * @param mixed $medias
     */
    public function setMedias($medias)
    {
        $this->medias = $medias;
    }
}


Et celui de PartnerMedia :

class PartnerMedia extends SortableEntity
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
    /**
     * @ORM\ManyToOne(targetEntity="\Application\Sonata\MediaBundle\Entity\Media")
     */
    private $medias;
 
    /**
     * @ORM\ManyToOne(targetEntity="\AppBundle\Entity\Partner", inversedBy="partner")
     *
     * @Gedmo\SortableGroup
     */
    private $partner;
 
 
    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }
 
    /**
     * Set medias
     *
     * @param Media $medias
     * @return PartnerMedia
     */
    public function setMedias(Media $medias = null)
    {
        $this->medias = $medias;
 
        return $this;
    }
 
    /**
     * Get medias
     *
     * @return Media
     */
    public function getMedias()
    {
        return $this->medias;
    }
 
    /**
     * Set Partner
     *
     * @param Partner $partner
     * @return PartnerMedia
     */
    public function setPartner(Partner $partner = null)
    {
        $this->partner = $partner;
 
        return $this;
    }
 
    /**
     * Get Partner
     *
     * @return Partner
     */
    public function getPartner()
    {
        return $this->partner;
    }
 
    public function getContextName()
    {
        return 'partner_media';
    }


Et enfin celui pour générer le formulaire :

protected function configureFormFields(FormMapper $formMapper)
    {
 
        $formMapper
            ->tab('Général')
                ->with('contenu')
                    ->add('libelle', null, array('label' => 'Partenaire de Tignes'))
                    ->add('url', 'url', array('required' => false))
                    ->add('mea', null, array('label'=>'Mise en avant','required' => false))
                ->end()
            ->end()
            ->tab('Gallerie')
                ->with('Images')
                    ->add(
                        'medias',
                        'sonata_type_collection',
                        array(
                            'required' => false
                        ),
                        array(
                            'edit' => 'inline',
                            'inline' => 'table',
                            'sortable' => 'position'
                        )
                    )
                ->end()
            ->end()
        ;
        parent::configureFormFields($formMapper);
 
    }


Au niveau de mysql j'ai le résultat qu'il me faut mais cette exception me rend dingue.