Symfony 信条类表继承和属性签名
我最初在这里发布了这个问题: 我有以下实体层次结构,MyProduct是通过类表继承映射的父实体:Symfony 信条类表继承和属性签名,symfony,doctrine-orm,sylius,Symfony,Doctrine Orm,Sylius,我最初在这里发布了这个问题: 我有以下实体层次结构,MyProduct是通过类表继承映射的父实体: SyliusProduct # Mapped superclass containing the 'options' association mapping –- MyProduct # Mapped superclass that should override the association (Head of CTI) ---- MyProduct1 # Ultimate ch
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级别
- 简单地忽略关联
<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继承,所有这些实体都位于一个表上,因此doctrine不会尝试为每个子产品创建具有相同名称的不同表。是否为每个产品创建新实体?是的,MyProduct[1,2,3,4]是扩展MyProduct的实体。您的问题是
产品
实体/表应该包含相同实体/表中的所有产品,而不是每个实体/表中的单个产品。是的,没错,我的问题是“是否可以使用类表继承来存储子产品,同时将“选项”关联保持在MyProduct级别?“在我看来,你在错误地查看数据库。为什么您需要将每个产品存储在单个实体中,而不是将它们全部存储在单个表中?如果您想添加另一个产品,那么您是否需要创建另一个实体并更改继承以配合它?