doctrine-orm - 教义2 : OneToMany on mapped superclass

标签 doctrine-orm relationship class-table-inheritance mappedsuperclass

我的数据库结构如下:

工作:

  • CTI工作
  • MappedSuperclass AbstractImageWork 扩展 工作
  • 决赛 table 摄影作品 扩展 AbstractImageWork

  • 评论:
  • MappedSuperclass评论
  • 决赛 table 工作评论 扩展 评论

  • 工作评论 具有多对一关系工作 :
    @ManyToOne(targetEntity="Work", inversedBy="comments")
    

    工作 具有 OneToMany 关系工作评论 :
    @OneToMany(targetEntity="WorkComment", mappedBy="work")
    

    问题是 Doctrine 在更新模式时给了我这个错误:
    [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 有关AbstractImageWork 卡在 之间工作 摄影作品 ,但我实际上并没有把这个关系放在 MappedSuperclass 上,而是放在 CTI 表上.. 那么为什么 Doctrine 会这样呢?

    有任何想法吗?

    最佳答案

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

    关于doctrine-orm - 教义2 : OneToMany on mapped superclass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13124225/

    相关文章:

    Symfony 2 无法使用 Composer 安装教义

    php - Laravel 对关系最轻查询的 Eloquent 搜索是什么?

    sql-server - 您如何在数据库中表示继承?

    mysql - 从类表继承确定类型

    forms - 将带有额外字段的多对多关系呈现为表单

    php - Symfony3 : How to delete current user and redirect to home?

    ios - RestKit 发布嵌套托管对象会创建重复项

    sql - 如何在 SQL 数据库中创建记录之间的关系?

    mysql - 当 null 时,如何让带有 where not 子句的 Doctrine 查询生成器返回值