我想要在一个实体上进行动态实体映射,其他实体将使用它。例如,我有一个文件实体,其将存储MIME类型,映射key,name等等,也是一个entity_id其中将包含ID的实体属于。映射key将确定类,因为此文件实体将是多对多的。因此,targetEntityfor File实体不是固定的。如何实现呢?
文件实体
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* File
*
* @ORM\Entity
*/
class File {
//.... Other mapping properties
/**
* @ORM\ManyToOne(targetEntity="SuperClass", inversedBy="files")
* @ORM\JoinColumn(name="entity_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $entity;
}
Run Code Online (Sandbox Code Playgroud)
产品实体
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Product
*
* @ORM\Entity
*/
class Product extends SuperClass {
//.... Other mapping properties
/**
* @ORM\OneToMany(targetEntity="File", mappedBy="entity")
*/
protected $files;
}
Run Code Online (Sandbox Code Playgroud)
但是,我还有许多其他类似于的实体, …