2014-06-17 80 views
2

我最初发布这个问题在这里:https://github.com/doctrine/DoctrineBundle/issues/297主义类表继承和财产ignoral

我有以下实体层次,myProduct的被父实体通过类表继承映射:

SyliusProduct # Mapped superclass containing the 'options' association mapping 
–- MyProduct  # Mapped superclass that should override the association (Head of CTI) 
---- MyProduct1 # Ultimate children (entities) 
---- MyProduct2 
---- MyProduct3 
---- MyProduct4 

SyliusProduct选项实体具有多对多关联,该实体映射在SyliusProduct的映射中。

我无法更改SyliusProduct(它是Symfony供应商的一部分)的映射。

当生成模式时,学说要为每个最终子代生成sylius_product_options表,该表抛出'tables exists'异常。

有没有办法要么:

  • 通过创建4个不同的 表映射在最终子级别的关系(和指定不同的表名)?
  • 映射它在MyProduct级别?
  • 干脆忽略这种关联?
+0

您是否为每个产品创建新实体? – qooplmao

+0

是的,MyProduct [1,2,3,4]是扩展MyProduct的实体。 – Christian

+0

您的问题是'产品'实体/表应该包含您的所有产品在同一个实体/表中,而不是每个产品。 – qooplmao

回答

0

这个问题是旧的,但你应该设置你的产品的实体继承型为单表(不设置子实体的表属性,否则你会得到一个错误,该表已经存在)

您还需要鉴别的地图添加到myProduct的实体对每个子产品,例如:

<entity name="MyProduct" inheritance-type="SINGLE_TABLE"> 
    <discriminator-map> 
     <discriminator-mapping value="pr1" class="MyProduct1"/> 
     <discriminator-mapping value="pr2" class="MyProduct2"/> 
     <discriminator-mapping value="pr2" class="MyProduct3"/> 
    </discriminator-map> 
    ... 
</entity> 

如果父映射超已经有了很多一对多选项映射你不应该重新定义它的您的MyProduct实体。

这样MyProduct1-4实体将从MyProduct继承,MyProduct本身从SyliusProduct继承,所有这些都在SINGLE_TABLE上,所以教义不会尝试为每个SubProduct创建具有相同名称的不同表。