Here’s what I’m trying to do:
I’ve got three tables:
Appointments Users and Shares –
I’d like to assign users to an appointment.
So what I did until now is that I created a table in between appointment and user which
stores the user_id and appointment_id which a user is assigned to.
I’m able to search the shares for a specific appointment in my appointments_controller
with
@shares = Shares.find(:all, :conditions => { :appointment_id => @appointment.id })
After that I get a hash @shares which looks like this:
[#<Shares id: 10, user_id: 3, appointment_id: 1, created_at: "2012-12-04 10:24:16", updated_at: "2012-12-04 10:24:17">, #<Shares id: 12, user_id: 2, appointment_id: 1, created_at: "2012-12-04 10:28:38", updated_at: "2012-12-04 10:28:39">]
What I’d like to do now is a query in the users table to find the usernames that belong to the user_ids i found in the shares hash.
I tried that with something like this:
@shares.each do |s|
@participants = User.all(:conditions => {:id => s.user_id})
end
But it doesn’t work because the participants hash gets overwritten every time the loop starts…
Thanks for your help
1 Answer