3
我有我想要爲其他實體(此時未知)的基類中使用的實體,我需要存儲基礎機構的關係:主義實體繼承
/**
* @ORM\Entity
* @ORM\Table(name="CMS_content")
*/
class BaseContent {
/**
* @ORM\ManyToOne(targetEntity="BaseContent")
* @ORM\JoinColumn(name="parent", referencedColumnName="id", unique=false)
*/
protected $parent;
/**
* @ORM\ManyToOne(targetEntity="ContentType")
* @ORM\JoinColumn(name="content_type", referencedColumnName="id", unique=false)
*/
protected $contentType;
...
};
/**
* @ORM\Entity
* @ORM\Table(name="CMS_whateverSpecializedContent")
*/
class WhateverSpecializedContent extends BaseContent {};
我不能使用@ORM\InheritanceType("JOINED")
因爲我希望能夠在不觸及基類的情況下創建任意數量的子類。我還需要將基類放在單獨的數據庫表中,這樣關係纔有意義。
我還有什麼其他選擇來管理這些結構?
您將在此處使用多表繼承方法。不知道爲什麼你不想手動更新基類? – busypeoples
@busypeoples基類是一個通用的cms包的一部分,可以在多個項目中重複使用,而不需要多個版本,我希望它通過定義專用的實體類型從其他包擴展實體。基本實體不應該知道它的子類。 – user1063963
您可能想閱讀:http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html –