问题描述
我的数据库结构如下:
工作:
- CTI表工作
- MappedSuperclass 表 AbstractImageWork 扩展了工作
- 决赛桌 PhotoWork 扩展了 AbstractImageWork
- CTI table Work
- MappedSuperclass table AbstractImageWork which extends Work
- final table PhotoWork which extends AbstractImageWork
评论:
- MappedSuperclass表评论
- 决赛桌WorkComment 扩展了Comment
WorkComment 与 Work 具有多对一关系:
WorkComment has a ManyToOne relation to Work:
@ManyToOne(targetEntity="Work", inversedBy="comments")
Work 与 WorkComment 有一对多的关系:
Work has a OneToMany relation to WorkComment:
@OneToMany(targetEntity="WorkComment", mappedBy="work")
问题是 Doctrine 在更新架构时给了我这个错误:
The problem is that Doctrine gives me this error while updating the schema:
[DoctrineORMMappingMappingException]
It is illegal to put an inverse side one-to-many or many-to-many association on
mapped superclass 'Acme...AbstractImageWork#comments'.
我猜这与卡在 Work 和 PhotoWork 之间的 MappedSuperclass AbstractImageWork 有关,但实际上我没有把这个关系放在 MappedSuperclass 上,但放在 CTI 表上..那么为什么 Doctrine 会这样呢?
I guess this has something to do with the MappedSuperclass AbstractImageWork stuck in the middle between Work and PhotoWork, but I didn't actually put this relation on the MappedSuperclass, but on the CTI table.. so why will Doctrine behave like this?
有什么想法吗?
推荐答案
在某些情况下,当您从标记为 @ORMMappedSuperclass
的类继承时出现此类错误,请尝试更改您的属性访问级别从私有到受保护
In some cases, when you have such error when inherit from the class that is tagged as @ORMMappedSuperclass
, try to change your properties access level from private to protected
这篇关于Doctrine2:映射超类上的单对多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!