symfony - Doctrine2/Symfony2-同一表上有多个实体

标签 symfony doctrine-orm multiple-inheritance mappedsuperclass

在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/

相关文章:

php - 尝试从命名空间 symfony Controller 调用函数

validation - Symfony 2, Doctrine 2 - 如何验证删除子父关系

php - 如何停止尝试为已映射到实体的 View 创建表的学说?

doctrine-orm - Symfony & Doctrine 2/加速查询

Java:可以访问父类(super class)字段和方法的策略模式?

forms - Symfony2 表单中的非空白文件输入字段

symfony - 如何在 Sonata Admin 中正确配置 'sonata_type_collection' 字段

php - 如何设置外键 ID #sf2 #doctrine2

python - 有没有一种好方法让一个类继承两个类之一

c++ - 多重(菱形)继承在没有 "virtual"的情况下编译,但没有