Doctrine2 / Symfony2 - 同一桌上的多个实体 [英] Doctrine2 / Symfony2 - Multiple entities on same table
问题描述
在Symfony2应用程序中,我有一个 MainBundle 和可以启用或不启用的不同的软件包。在 MainBundle 中,我需要使用模型和基本的实体。在实体 实体 实体中,实体 实体 b
MainBundle中的装置需要加载有或没有其他捆绑包,而不是MainBundle:
MainBundle
- 模型
- 实体(表名test)
- Fixtures
OtherBundle
- 实体(表名test)
- Fixtures
OtherBundle2
- 实体(表名=test)
- Fixtures
如果我对模型使用了 @ ORM\MappedSuperclass ,则 @ ORM\\Entity 对于实体实体 实体 存在。
我不能使用继承表作为我的模型,不需要了解其他bundle中的其他实体。 @ ORM\DiscriminatorMap 不能指向 OtherBundle 。
有没有办法呢? p>
如Jasper N. Brouwer所提到的,它实际上是同一个实体和同一个表,所以没有任何意义,
在名为SharedEntityBundle的包中创建您的实体,并使用 resolve_target_entity 与其他捆绑的实体相关联没有他们知道彼此。
http://symfony.com/doc/current/cookbook/doctrine/resolve_target_entity.html
正在说,似乎有一个多个实体经理的解决方案:
Symfony 2 / Doctrine 2:同一张表中的两个实体,使用一个赞成另一个
In a Symfony2 application I have a MainBundle and distinct bundles which can be enabled or not. In the MainBundle I need to have the Model and a basic Entity. In an OtherBundle an Entity with the same table name than Entity in MainBundle.
Fixtures in MainBundle need to be loaded with or without the other bundles than MainBundle :
MainBundle
- Model
- Entity (Table name "test")
- Fixtures
OtherBundle
- Entity (Table name "test")
- Fixtures
OtherBundle2
- Entity (Table name="test")
- Fixtures
If i used the @ORM\MappedSuperclass for the Model, a @ORM\Entity for the Entity in MainBundle and @ORM\Entity in OtherBundle then Doctrine2 stop with the error "table already exists".
I cant use the Inheritance table as my model dont need to know about other entities in the other bundles. The @ORM\DiscriminatorMap cant point to OtherBundle.
Is there a way to do this ?
As mentioned by Jasper N. Brouwer it's esentially the same entity and the same table, so there is no point in doing what you're trying to do.
Create your entity in a bundle named for example "SharedEntityBundle" and use resolve_target_entity to relate to this entity from other bundles without them knowing about eachother.
http://symfony.com/doc/current/cookbook/doctrine/resolve_target_entity.html
That being said, there seems to be a solution with multiple entity managers: Symfony 2 / Doctrine 2: Two Entities for the same table, use one in favour of the other
这篇关于Doctrine2 / Symfony2 - 同一桌上的多个实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!