Symfony,doctrine不允许删除关联setEntity(null)

时间:2016-07-20 13:56:36

标签: symfony doctrine-orm doctrine

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

Devis实体:

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;

我试图从教义:http://docs.doctrine-project.org/en/latest/reference/working-with-associations.html#removing-associations

中删除文档
    $devis = $em->getRepository('DevisBundle:Devis')->findOneById($devisId);
    $client = $em->getRepository('DevisBundle:Client')->findOneById($devis->getClient());

    $client->getDevis()->removeElement($devis);
    $devis->setClient(null);

    //$em->persist($devis);
    $em->flush();
    dump($devis);

但我有这个错误:

  

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

1 个答案:

答案 0 :(得分:3)

像这样更改你的方法:

var table = $('#example').DataTable();

$('#example tbody').on( 'click', 'tr', function () {
    var data = table.row( this ).data();

    data.digit.current_value++;

    table
        .row( this )
        .data( data )
        .draw(false);
} );

这也是使用命令doctrine:generate:entities。

生成的方式