我正在为一个 Symfony 项目而苦苦挣扎,而且由于我对框架没有那么丰富的经验,我无法弄清楚我是否有设计缺陷,如果 Symfony 无法处理我的用例,或者我是否只需要找到正确的方法。
这里是 :
我有一个实体行,它应该包含 1 到 n 个具有不同内容的项目,如“标题”、“文本”、“图像”等。
由于每个内容都有不同的特征,我通过单表继承从一个名为 RowContent 的抽象类扩展了每个内容类型。这是实体的编辑版本:类行
class Row
{
//.....
/**
* @var ArrayCollection $rowContents
*
* @ORM\OneToMany(targetEntity="RowContent", mappedBy="row", cascade={"persist", "remove", "merge"})
*/
private $rowContents;
//...
}
Run Code Online (Sandbox Code Playgroud)
行内容类:
/**
* RowContent
*
* @ORM\Table(name="row_content")
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({
* "title" = "Kinkinweb\BaseBundle\Entity\Content\Title",
* "text" = "Kinkinweb\BaseBundle\Entity\Content\Text",
* "image" = "Kinkinweb\BaseBundle\Entity\Content\Image",
* })
* @ORM\Entity(repositoryClass="Kinkinweb\BaseBundle\Repository\RowContentRepository")
*/
abstract class RowContent
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* …Run Code Online (Sandbox Code Playgroud)