Doctrine2: OneToMany on mapped superclass

流过昼夜 提交于 2019-12-01 01:10:09

问题


My DB structure is as follows:

work:

  • CTI table Work
  • MappedSuperclass table AbstractImageWork which extends Work
  • final table PhotoWork which extends AbstractImageWork

comment:

  • MappedSuperclass table Comment
  • final table WorkComment which extends Comment

WorkComment has a ManyToOne relation to Work:

@ManyToOne(targetEntity="Work", inversedBy="comments")

Work has a OneToMany relation to WorkComment:

@OneToMany(targetEntity="WorkComment", mappedBy="work")

The problem is that Doctrine gives me this error while updating the schema:

[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'.

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?

Any ideas?


回答1:


In some cases, when you have such error when inherit from the class that is tagged as @ORM\MappedSuperclass, try to change your properties access level from private to protected



来源:https://stackoverflow.com/questions/13124225/doctrine2-onetomany-on-mapped-superclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!