2014-03-25 69 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有没有可能?

回答