Search code examples
phpsymfonyvichuploaderbundle

How to define mappings with OneToMany relation | VichUploaderBundle


Is it possible to define mapping on OneToMany Or OneToOne relation within parent Entity ? I don't find any documentation for the moment about that.

Actually done:

Entity;

/**
* @ORM\OneToOne(targetEntity="Asset", cascade={"persist", "remove"})
*/
private $image;

Asset:

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

    /**
     * @var File
     */
    private $imageFile;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $imageName;

EntityType:

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('aaset', AssetType::class, [
                'label' => 'label'
            ])

Asset Type:

public function buildForm(FormBuilderInterface $builder, array $options){
$builder
            ->add('imageFile', VichImageType::class, [
                'label'        => 'Image',
                'required'     => false,
                'allow_delete' => false,
                'download_uri' => false,
                'image_uri'    => true
            ])

VichUploader Definition for Asset:

App\Entity\Asset:
  imageFile:
    mapping: images
    filename_property: imageName

VichUploader Definition for Entity:

App\Entity\Entity:
  oneToOne:
    image:
      mapping: other_mapping
      filename_property: imageName

Someone already solve this problem ? Thanks for your help.

Tony


Solution

  • The @NicolaiFröhlich answer is correct, I need to use directory namer.