persist方法在继承类中不起作用,尽管我已在批注(cascade =“ all”)中设置了级联属性。
/**
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="tipo", type="string")
* @ORM\DiscriminatorMap({"menu" = "Menu", "enquete" = "Enquete"})
*/
abstract class Widget{
/**
* @ORM\Id
*/
protected $id;
}
/**
* @ORM\Entity
*/
class Enquete extends Widget{
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="Admin\Model\Alternativa", mappedBy="enquete", cascade="all")
*/
protected $alternativas;
}
/**
* @ORM\Entity
*/
class Alternativa{
/**
* @ORM\ManyToOne(targetEntity="Admin\Model\Enquete", inversedBy="alternativas")
* @ORM\joinColumn(name="Enquete_id", referencedColumnName="id")
*/
protected $enquete;
}
我在级联中使用持久性,但不起作用:
$enquete->addAlternativa(New Alternativa());
$entityManager->persist($enquete);
$entityManager->flush();
结果是跟随错误:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'Enquete_id' cannot be null