How to get these records in has_and_belongs_to_many relation


#1

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, users_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 :wink: )

these are my users:
in group: Luc
not in group: Nick, Glenn, Andy

for the second colum i got this in my controller:
@group_users = Group.find(:first, :conditions =>[‘firm_id = ? and id =
?’,
@firm_id, @selected_group]).users

and in rhtml:
<% for user in @group_users %>
<%= user.first_name %>

<% end %>

the output it get: Luc
(this is correct for the user who are in the group)

Bur now: who do i get the users Nick, Glenn and Andy???

Thanks in advance