Symfony,不允许删除集合实体(null)

Symfony,不允许删除集合实体(null),symfony,doctrine-orm,doctrine,Symfony,Doctrine Orm,Doctrine,我需要删除具有以下关系的两个对象之间的关联 设计实体: class Devis { /** * @var \stdClass * * @ORM\ManyToOne(targetEntity="DevisBundle\Entity\Client", inversedBy="devis", cascade={"persist"}) * @ORM\JoinColumn(nullable=false, nullable=true) */ private $client; /** * Set

我需要删除具有以下关系的两个对象之间的关联

设计实体:

class Devis
{
 /**
 * @var \stdClass
 *
 * @ORM\ManyToOne(targetEntity="DevisBundle\Entity\Client", inversedBy="devis", cascade={"persist"})
 * @ORM\JoinColumn(nullable=false, nullable=true)
 */
private $client;
/**
 * Set client
 *
 * @param \DevisBundle\Entity\Client $client
 * @return Devis
 */

public function setClient(\DevisBundle\Entity\Client $client)
{
    $this->client = $client;

    return $this;
}
客户实体:

class Client
{
 /**
 * @var \stdClass
 *
 * @ORM\OneToMany(targetEntity="DevisBundle\Entity\Devis", mappedBy="client", cascade={"remove"})
 */
private $devis;
我试着按照条令的要求来做:

但我有一个错误:

可捕获的致命错误:传递给DevisBundle\Entity\Devis::setClient()的参数1必须是DevisBundle\Entity\Client的实例,给定null,在…中调用


按如下方式更改设置方法:

public function setClient(\DevisBundle\Entity\Client $client = null)
{
    $this->client = $client;

    return $this;
}

这也是使用命令条令生成的方式:生成:实体。

谢谢!我不明白为什么我的setter中没有$client=null,我使用命令原则生成了这个setter:generate:entities…您第一次生成属性注释时是否使用了“nullable=true”?setter只创建了一次,如果您再次生成实体,它只会添加不存在的setter和getter。我不记得了,我很久以前就生成了这个setter。不管怎样,下次我会记得的。
public function setClient(\DevisBundle\Entity\Client $client = null)
{
    $this->client = $client;

    return $this;
}