[Symfony2]: deleting the cascading element of an object. How to get lifecycle attribute
I am using symfony 2.7 as CMF.
I have 2 users and a Mission. the mission has a lifecycle attribute (createdBy, updatedBy).
when i try to delete user i have this error:
SQLSTATE [23000]: Integrity constraint violation: 1451 Unable to delete or update parent row: foreign key constraint fails (
XXXX
.mission
, CONSTRAINTFK_19653DBD16FE72E1
FOREIGN KEY (updated_by
) REFERENCESfos_user_user
(id
))
this is my lifecycle in entity mission:
/**
* @ORM\ManyToOne(targetEntity="Application\Sonata\UserBundle\Entity\User")
* @ORM\JoinColumn(name="created_by", referencedColumnName="id" , onDelete="CASCADE")
*/
private $createdBy;
/**
* @ORM\ManyToOne(targetEntity="Application\Sonata\UserBundle\Entity\User")
* @ORM\JoinColumn(name="updated_by", referencedColumnName="id" , onDelete="CASCADE")
*/
private $updatedBy;
thanks for the reference.
source to share
Put this on your user-side doctrine relation, for example:
* @ORM\OneToMany(targetEntity="your\entity\mission", cascade={"delete"})
EDIT:
If you can't access the custom object (can't see why you can't ...) you can do something a little ugly like get the mission attached to the user, delete it and then delete the user
source to share