我需要一些使用"多态关联"的学说2的帮助.让我澄清一下自己.实体可以使用多态关系的子集来支持文件附件.File实体用于保护这种关系,其中对文件的引用作为记录存储在files表中,并与父模型具有多态关系.我想创建与https://octobercms.com/docs/database/attachments相同的功能 但是不知道如何建立关系,以及如何使attachment_type像attachment_id一样动态;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
*
* @ORM\OneToOne(targetEntity="App\Domain\FileAttachment\Entity\FileAttachment", attachment_type="news_thumbnail")
*/
private $thumbnail;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
*
* @ORM\OneToOne(targetEntity="App\Domain\FileAttachment\Entity\FileAttachment", attachment_type="news_image")
*/
private $image;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Domain\FileAttachment\Entity\FileAttachment", attachment_type="news_files")
*/
private $files;
Run Code Online (Sandbox Code Playgroud)
文件表的一个例子.