简体   繁体   中英

Best way to remove all associations has_and_belongs_to_many without deleting the records

I have a user model that has_and_belongs_to_many :clubs so I can seen eg clubs.users and it returns all the users for that club. What I want to do is remove/break the associations all the users for that club. I want the users to still exist but just not be associated to that club anymore.

I am aware of eg club.users.delete_all but that ended up deleting the users as well. I cannot think of another way to approach this for removing all of the records.

Worth noting I know you can do club.users.delete(user) I am unsure how to pass in all the users associated to that club to that method. Any help would be much appreciated.

将俱乐部用户设置为空数组将破坏该关系而不损害任何一个实体!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM