hey, i my database i have users and groups, each user can get in different groups my db structure: table groups: id, name, basegroup, firm_id table users: id, firstname, lastname, email table groups_users: group_id, user_id my relation is a many to many: class Group < ActiveRecord::Base has_and_belongs_to_many :users end class User < ActiveRecord::Base has_and_belongs_to_many :groups end i want this http://wiki.script.aculo.us/scriptaculous/show/SortableListsDemo with ajax, first column the user who arent in the group, the second column those who are in the group. (is cooler than 2 oldschool selectlists ;) ) now i want to delete this record ex: (i want to remove the link between the user and the group, but wanna keem the user and group object group_id = 5 users_id = 10 User.connection.delete("DELETE * FROM groups_users WHERE group_id = " + group_id + " and user_id = " + users_id) Anyone can help me?
collection.delete(object, ...) - removes one or more objects from the collection by removing their associations from the join table. This does not destroy the objects Brutyn Nick wrote:>hey, >i my database i have users and groups, each user can get in different groups > >my db structure: >table groups: id, name, basegroup, firm_id >table users: id, firstname, lastname, email >table groups_users: group_id, user_id > >my relation is a many to many: >class Group < ActiveRecord::Base > has_and_belongs_to_many :users >end >class User < ActiveRecord::Base > has_and_belongs_to_many :groups >end > >i want this http://wiki.script.aculo.us/scriptaculous/show/SortableListsDemo >with ajax, first column the user who arent in the group, the second column those >who are in the group. (is cooler than 2 oldschool selectlists ;) ) > >now i want to delete this record ex: (i want to remove the link between the user >and the group, but wanna keem the user and group object >group_id = 5 >users_id = 10 > >User.connection.delete("DELETE * FROM groups_users WHERE group_id = " + group_id >+ " and user_id = " + users_id) > >Anyone can help me? > > > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > >
On 12/15/05, Brutyn Nick <brutyn_nick@hotmail.com> wrote:> hey, > i my database i have users and groups, each user can get in different groups > > my db structure: > table groups: id, name, basegroup, firm_id > table users: id, firstname, lastname, email > table groups_users: group_id, user_id > > my relation is a many to many: > class Group < ActiveRecord::Base > has_and_belongs_to_many :users > end > class User < ActiveRecord::Base > has_and_belongs_to_many :groups > end > > i want this http://wiki.script.aculo.us/scriptaculous/show/SortableListsDemo > with ajax, first column the user who arent in the group, the second column those > who are in the group. (is cooler than 2 oldschool selectlists ;) ) > > now i want to delete this record ex: (i want to remove the link between the user > and the group, but wanna keem the user and group object > group_id = 5 > users_id = 10 > > User.connection.delete("DELETE * FROM groups_users WHERE group_id = " + group_id > + " and user_id = " + users_id) > > Anyone can help me?From the API Docs: http://rails.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000474 collection.delete(object, …) - removes one or more objects from the collection by removing their associations from the join table. This does not destroy the objects. @users.groups.delete(@group) or @groups.users.delete(@user) -- rick http://techno-weenie.net _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails