views:

280

answers:

3

Hi All,

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.

+1  A: 

You can't unless the tables are set to cascade on delete.

Coronatus
+1  A: 

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'));
takeshin
+1  A: 

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.

Goran Jurić
You are right. What was I thinking?
Moon