如何使用 OneToMany 关系定义映射 | VichUploaderBundle
How to define mappings with OneToMany relation | VichUploaderBundle
是否可以在父实体中的 OneToMany 或 OneToOne 关系上定义映射?我暂时找不到任何相关文件。
实际完成:
实体;
/**
* @ORM\OneToOne(targetEntity="Asset", cascade={"persist", "remove"})
*/
private $image;
资产:
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;
实体类型:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('aaset', AssetType::class, [
'label' => 'label'
])
资产类型:
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 定义:
App\Entity\Asset:
imageFile:
mapping: images
filename_property: imageName
实体的 VichUploader 定义:
App\Entity\Entity:
oneToOne:
image:
mapping: other_mapping
filename_property: imageName
有人已经解决了这个问题?
谢谢你的帮助。
托尼
@NicolaiFröhlich 的回答是正确的,我需要使用目录命名器。
是否可以在父实体中的 OneToMany 或 OneToOne 关系上定义映射?我暂时找不到任何相关文件。
实际完成:
实体;
/**
* @ORM\OneToOne(targetEntity="Asset", cascade={"persist", "remove"})
*/
private $image;
资产:
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;
实体类型:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('aaset', AssetType::class, [
'label' => 'label'
])
资产类型:
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 定义:
App\Entity\Asset:
imageFile:
mapping: images
filename_property: imageName
实体的 VichUploader 定义:
App\Entity\Entity:
oneToOne:
image:
mapping: other_mapping
filename_property: imageName
有人已经解决了这个问题? 谢谢你的帮助。
托尼
@NicolaiFröhlich 的回答是正确的,我需要使用目录命名器。