Deleting record in many-to-many table

前端 未结 2 1234
滥情空心
滥情空心 2020-12-15 06:39

I\'m following the security chapter of the Symfony 2 book.

There\'s is an example with a table USERS and GROUPS. There is a many-to

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 06:56

    In addition to @Ethan's answer, one-way remove is not working. For such manyToMany relationship, you have to call the remove methods from both entities, for example,

    $user = $em->findOneById($userId);
    $group = $em->findOneById($groupId);
    
    $user->removeGroup($group);
    $group->removeUser($user);
    
    $em->persist($user);
    $em->flush();
    

提交回复
热议问题