How to implement many-to-many relationships in Sonata Media Bundle

前端 未结 2 796
一向
一向 2021-02-01 06:00

I am trying to relate SonataMediaBundle to another Entity: Products with a relation ManyToMany.

The schema and relation are well created.

Howev

2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-01 06:53

    You need to rely on MediaBundle Gallery. In your entity you something like :

    /**
     * @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Gallery")
     * @ORM\JoinColumn(name="image", referencedColumnName="id")
     */
    private $images;
    

    And then in your form, you'll be able to link a Gallery to your object with something like :

    ->add('images', 'sonata_type_model_list', array('required' => false), array('link_parameters' => array('context' => $context)))
    

提交回复
热议问题