2016-07-28 113 views
2

我想要做的就是從映射超類擴展一個表繼承類,但是當我嘗試更新的方案,我去以下錯誤:主義單表繼承從擴展映射的超

[Doctrine\DBAL\Schema\SchemaException]
An index with name 'uniq_efe84ad134ecb4e6' was already defined on table 'article_article'.

我層次:

內容(mappedSuperClass)< - 第(SingleTableInheritance)< - MyArticle

類:

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 

請告訴我錯在這裏?

回答

0

錯誤在mappedSuperclass上。 Content類有一個oneToOne關係,這不在上面的例子中,因爲我試圖使它更抽象。

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

看起來像教條試圖再次爲擴展類添加唯一的關鍵。我不知道這是限制到mappedSuperclass還是隻是一個bug,但我解決了它由改變oneToOne關係到manyToOne,因爲它幾乎相同,但沒有一個唯一的約束。

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