简体   繁体   English

Symfony2 Doctrine2继承另一个捆绑中的实体

[英]Symfony2 Doctrine2 Inheriting an Entity in another Bundle

Trying to create 2 bundles. 尝试创建2个捆绑包。 One is a portal and the other is a training bundle. 一个是门户,另一个是培训包。 The thing that I'm having trouble grasping is how to create an entity in the portal bundle that inherits an entity in the training bundle (and overwrites the training bundles entity). 我遇到的麻烦是如何在门户捆绑中创建一个实体,该实体继承培训捆绑中的实体(并覆盖培训捆绑实体)。

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

Is this even possible? 这有可能吗? I tried creating the TrainingBundle:Course Entity as a MappedSuperClass but this is not possible because the TrainingBundle:Course entity has a One to many relationship. 我尝试将TrainingBundle:Course实体创建为MappedSuperClass,但这是不可能的,因为TrainingBundle:Course实体具有一对多关系。

If I try to just extend the TrainingBundle:CourseEntity I get an error "The table with name 'Course' already exists. 如果我尝试仅扩展TrainingBundle:CourseEntity,则会收到错误消息“名称为'Course'的表已存在。

I think you are looking for a mapped superclass - http://doctrine-orm.readthedocs.org/en/2.0.x/reference/inheritance-mapping.html . 我认为您正在寻找映射的超类-http: //doctrine-orm.readthedocs.org/en/2.0.x/reference/inheritance-mapping.html

If the restrictions on a mapped superclass don't work for your use case you may have to look at Class Table Inheritance to extend your entities. 如果对映射的超类的限制不适用于您的用例,则可能必须查看“类表继承”以扩展您的实体。 Class Table Inheritance is described a little further down on that same page. “类表继承”在同一页的后面部分进行了介绍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM