Doctrine orm Doctrine2:映射超类上的一个域

Doctrine orm Doctrine2:映射超类上的一个域,doctrine-orm,relationship,class-table-inheritance,mappedsuperclass,Doctrine Orm,Relationship,Class Table Inheritance,Mappedsuperclass,我的数据库结构如下: 工作: 表工作 表AbstractImageWork扩展了Work 最终表格摄影作品扩展了抽象影像作品 评论: 表注释 最终表格WorkComment扩展了Comment 工作评论与工作有多种关系: @ManyToOne(targetEntity="Work", inversedBy="comments") @OneToMany(targetEntity="WorkComment", mappedBy="work") 工作与工作评论有着千丝万缕的联系: @Man

我的数据库结构如下:

工作:

  • 工作
  • AbstractImageWork扩展了Work
  • 最终表格摄影作品扩展了抽象影像作品
评论:

  • 注释
  • 最终表格WorkComment扩展了Comment
工作评论工作有多种关系:

@ManyToOne(targetEntity="Work", inversedBy="comments")
@OneToMany(targetEntity="WorkComment", mappedBy="work")
工作工作评论有着千丝万缕的联系:

@ManyToOne(targetEntity="Work", inversedBy="comments")
@OneToMany(targetEntity="WorkComment", mappedBy="work")
问题是,在更新模式时,条令给了我这个错误:

[Doctrine\ORM\Mapping\MappingException]
It is illegal to put an inverse side one-to-many or many-to-many association on
mapped superclass 'Acme\...\AbstractImageWork#comments'.

我猜这与MappedSuperclass <强> ActudiTimeWorks<强>卡在<强>工作< /强>和<强> PoopWORK < /强>之间,但实际上我并没有把这个关系放在MappedSuperclass上,而是在CTI表上。那么,为什么教义会有这样的表现呢


有什么想法吗?

在某些情况下,当您从标记为
@ORM\MappedSuperclass
的类继承时出现此类错误,尝试将您的属性访问级别从private更改为protected

在其他情况下,当您在抽象上级类中声明
@ORM\Entity
而不是
@ORM\MappedSuperclass

映射的超类不能是实体,它是不可查询的,并且由映射的超类定义的持久关系必须是单向的(仅限拥有方)这意味着映射的超类上根本不可能存在一对多关联。此外,只有当映射的超类此时仅在一个实体中使用时,才可能存在多对多关联。为了进一步支持继承,必须使用单表或联接表继承特性


看看这里:

奇怪的是,这个解决方案对我不起作用。我遇到了(几乎完全一样)相同的问题,我所有实体的属性都已经“受保护”。我试着把它们改成“公共的”,但没有用。