Reputation: 22565
I am trying to delete records in many to many using Doctrine. I used code on http://www.doctrine-project.org/documentation/manual/1_2/ru/working-with-models#many-to-many-relations:deleting-a-link
when I do the first method, it just deletes UserGroup record ONLY. How do I delete User, Group, and UserGroup records at once? The second and thrid methods do not work as well.
Upvotes: 0
Views: 2662
Reputation: 1839
You can use DQL to delete these records, but..
Are you sure that you want to do that? Before deleting all of them you should make sure that there is no other user using the group you are deleting and that the user you are deleting does not belong to any other groups.
Upvotes: 3
Reputation: 50648
Add in your schema.yml something in this mood:
...
relations:
...
onDelete: CASCADE
or in your base model:
$this->hasMany('Group as Groups', array(
...
'onDelete' => 'CASCADE'));
Upvotes: 2