2012-07-24 119 views
1

嘗試創建2個包。一個是門戶,另一個是培訓包。我難以掌握的是如何在繼承了訓練包中的實體的門戶束中創建實體(並覆蓋訓練束實體)。Symfony2 Doctrine2在另一個包中繼承實體

PortalBundle 
    Course Entity Extends TrainingBundle Course 
    Add a Many to Many Relationship with another PortalBundle Entity 


TrainingBundle 
    Course Entity 
    One to Many Relationship with Lesson Entity 

這甚至可能嗎?我嘗試創建TrainingBundle:Course Entity作爲MappedSuperClass,但這不可行,因爲TrainingBundle:Course實體具有一對多關係。

如果我嘗試只是延長TrainingBundle:。CourseEntity我得到一個錯誤「與名‘課程’已經存在

+0

你是如何映射實體?Yaml,XML,註釋? – Florent 2012-07-24 16:15:43

+0

當前我將它們映射爲註釋 – Heyflynn 2012-07-24 17:38:36

回答

0

我認爲你正在尋找一個映射的超表 - http://doctrine-orm.readthedocs.org/en/2.0.x/reference/inheritance-mapping.html

如果對映射超類的限制對你的用例不起作用,你可能不得不看看類表繼承來擴展你的實體類表繼承在這個頁面上稍微有些描述

+1

Mapped Superclass將不起作用,因爲我希望TrainingBundle保持可移植性,使TrainingBundle:課程關係保持機動(即1m課程)。如果我可以在PortalBundle中聲明InheritanceType和DiscriminatorColumn/Map,則類表繼承可能會有效。接下來我會嘗試一下。 – Heyflynn 2012-07-25 14:22:59