2014-03-25 71 views
0

我有以下實體授權NULL:學說:在國外複合鍵

/** 
* SeriesAuthorRole 
* 
* @ORM\Table() 
* @ORM\Entity(repositoryClass="Blog\Bundle\CoreBundle\Entity\SeriesAuthorRoleRepository") 
*/ 
class SeriesAuthorRole extends AuthorRoleAbstract 
{ 
    /** 
    * @var Series 
    * 
    * @ORM\ManyToOne(targetEntity="Blog\Bundle\CoreBundle\Entity\Series", inversedBy="authors") 
    * @ORM\JoinColumn(name="series", referencedColumnName="id", nullable=false) 
    * @ORM\Id 
    */ 
    private $series; 

    /** 
    * @var Author 
    * 
    * @ORM\ManyToOne(targetEntity="Blog\Bundle\CoreBundle\Entity\Author") 
    * @ORM\JoinColumn(name="author", referencedColumnName="id", nullable=false) 
    * @ORM\Id 
    */ 
    protected $author; 

    /** 
    * @var Role 
    * 
    * @todo Must be nullable 
    * 
    * @ORM\ManyToOne(targetEntity="Blog\Bundle\CoreBundle\Entity\Role") 
    * @ORM\JoinColumn(name="role", referencedColumnName="id", nullable=true) 
    * @ORM\Id 
    */ 
    protected $role; 

    // ... Getters, setters 
} 

背後的想法很簡單:我們有作家,作用和一系列的實體。一個系列可以有幾個不同角色的作者。同一作者可以在一個系列中實現多個角色。

有時,我們並不確切知道作者的作用。在這種情況下,NULL值將用於角色,NULL值代表「我不知道」。

我被教導不要在外國複合鍵中使用NULL,除非它有意義。那麼它在這裏有意義,我知道這可以在沒有Doctrine的情況下實現。然而,現在,Symfony 2拋出該錯誤:

Entity of type Blog\Bundle\CoreBundle\Entity\BandAuthorRole is missing an assigned ID for field 'role'. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly. 
500 Internal Server Error - ORMException 

那麼我怎樣才能授權外國複合鍵的NULL值? Doctrine有沒有可能?

回答