Answer the question
In order to leave comments, you need to log in
Doctrine OneToMany and ManyToOne, how to write cascading deletion?
I can not achieve in any way that when deleting one entity, the key in the entity associated with it is nullified. for example
/**
* @ORM\OneToMany(targetEntity="User", mappedBy="division")
*/
private $users;
/**
* @ORM\ManyToOne(targetEntity="Division", inversedBy="users")
* @ORM\JoinColumn(name="division_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $division;
Answer the question
In order to leave comments, you need to log in
onDelete and others in JoinColumn - executed on the database side
(Check the database for this value - 99% that the cascade operation for deletion hangs in the database itself)
cascade={...} This is a programmatic implementation of these events (Driven by doctrine)
In your case , even if you remove all the doctrine settings for cascading operations, I'm sure that the associated entity will still be deleted, so the doctrine has nothing to do with it.
class User {
/**
* @ORM\OneToMany(targetEntity="Division", mappedBy="division")
*/
private $users;
}
class Division {
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="users")
* @ORM\JoinColumn(name="division_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $division;
}
$user->getUsers()->isEmpty()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question