Answer the question
In order to leave comments, you need to log in
How to delete entities that have relationships?
The user needs to be deleted.
Wrote this code
$notification = $user->getNotificationSettings();
$em->remove($notification);
$groups = $user->getGroups();
foreach ($groups as $value) {
$em->remove($value);
}
$myShops = $user->getMyShops();
foreach ($myShops as $value) {
$em->remove($value);
}
$referrals = $user->getReferrals();
foreach ($referrals as $value) {
$em->remove($value);
}
$em->remove($user);
$em->flush();
Answer the question
In order to leave comments, you need to log in
If you want to delete links, use cascade delete (or SET NULL). Something like this:
//* @Entity */
class Group
{
/**
* @ManyToMany(targetEntity="User")
* @JoinTable(
* joinColumns={@JoinColumn(onDelete="CASCADE")},
* inverseJoinColumns={@JoinColumn(onDelete="CASCADE")}
* )
*/
private $users;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question