【问题标题】:Doctrine Single Table Inheritance extends from Mapped SuperclassDoctrine 单表继承扩展自映射超类
【发布时间】:2016-07-28 15:59:57
【问题描述】:

我想做的是从映射的超类扩展单个表继承类,但是当我尝试更新方案时出现以下错误:

[Doctrine\DBAL\Schema\SchemaException]
名称为“uniq_efe84ad134ecb4e6”的索引已在表“article_article”上定义。

我的层次结构:

内容(mappedSuperClass)

类:

abstract class Content
{
    protected $id;

    public function getId()
    {
        return $this->id;
    }
}

class Article extends Content
{

}

class MyArticle extends Article
{

}

映射:

Content:
    type: mappedSuperclass
    id:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO


Article:
    type: entity
    table: article_article
    inheritanceType: SINGLE_TABLE
    discriminatorColumn:
        name: discr
        type: string
    discriminatorMap:
        article: Article
        my_article: MyArticle

MyArticle:
    type: entity

这里有什么问题?

【问题讨论】:

    标签: symfony inheritance doctrine


    【解决方案1】:

    错误出现在 mappedSuperclass 上。 Content 类有一个 oneToOne 关系,这在上面的例子中没有,因为我试图让它更抽象。

    Content:
        # ...
        oneToOne:
            route:
                targetEntity: Route
    

    似乎学说尝试再次为扩展类添加唯一键。我不知道这是对 mappedSuperclass 的限制还是只是一个错误,但我通过 将 oneToOne 关系更改为 manyToOne 解决了它,因为它几乎相同,但没有唯一约束。

    Content:
        # ...
        manyToOne:
            route:
                targetEntity: Route
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-19
      • 2023-03-06
      • 2011-05-15
      • 1970-01-01
      相关资源
      最近更新 更多