在Symfony2应用程序中,我有一个 MainBundle 和可以启用或禁用的单独捆绑包。在 MainBundle 中,我需要拥有模型和基本的实体。在 OtherBundle 中,实体的表名与 MainBundle 中的实体相同。
MainBundle中的灯具需要与MainBundle一起加载或不加载其他捆绑包:
MainBundle
- Model
- Entity (Table name "test")
- Fixtures
OtherBundle
- Entity (Table name "test")
- Fixtures
OtherBundle2
- Entity (Table name="test")
- Fixtures
如果我将模型使用 @ORM\MappedSuperclass ,将 MainBundle 和 @octt_strong中的 @ORM\ @ orgt_strong表已经存在”。
我无法使用继承表,因为我的模型不需要了解其他捆绑软件中的其他实体。 @ORM\DiscriminatorMap 无法指向 OtherBundle 。
有没有办法做到这一点 ?
最佳答案
正如Jasper N. Brouwer所提到的,它本质上是相同的实体和相同的表,因此执行您想做的事情毫无意义。
在名为“SharedEntityBundle”的捆绑包中创建您的实体,并使用resolve_target_entity从其他捆绑包中与此实体建立关联,而他们彼此之间并不了解。
http://symfony.com/doc/current/cookbook/doctrine/resolve_target_entity.html
就是说,似乎有多个实体管理器的解决方案:
Symfony 2 / Doctrine 2: Two Entities for the same table, use one in favour of the other
关于symfony - Doctrine2/Symfony2-同一表上有多个实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18206201/