My HABTM joins seem to be working for the most part. Yes! Now I''m trying to create two lists on my project page of joined and unjoined contacts. To list the contacts that are joined to my project I use: <% mycontacts = @project.contacts %> then use a for loop to display a checkbox next to each record so I can select it to un-join them. I''m stumped on how to list contacts that are not joined though. I''d like to have checkboxes next to them so they can be added to the joined list. Eventually I also hoping to have multiple lists of un-joined contacts for contractors, developers, designers, and such which can be added to the project (filtering the not joined contacts by role). This starts to work when first loaded but then after addding contacts it no longer discriminates and trying to unjoin previous selections stops working. Hard coding the project_id won''t work in the final also: <% mycontacts = Contact.find(:all, :joins => ''INNER JOIN contacts_projects ON contacts.id != contacts_projects.contact_id WHERE (contacts_projects.project_id = 3 )'' ) %> Any help appreaciated. Maybe there are some more in-depth HABTM tutorials posted somewhere? DAN -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2006-Nov-06 14:00 UTC
Re: How do I list items not ''joined'' to the current record?
Something along the lines of Contact.find :all, :joins => ''LEFT OUTER JOIN contacts_projects on contacts.id = contacts_projects.contact_id'', :conditions => ''contacts_projects.project_id IS NULL'' should get you all contacts which don''t have any projects assigned to them. Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Cayce Balara
2006-Nov-06 19:14 UTC
Re: How do I list items not ''joined'' to the current record?
Just grab all contacts, and filter out the ones that are included in the current project''s contacts. As in... not_my_contacts = Contact.find(:all).collect {|c| c unless @project.contacts.include?(c) } This could be expanded for your future needs... not_my_developers = Contact.find(:all, :conditions => "role = ''DEVELOPER''").collect {|c| c unless @project.contacts.include?(c) } etc. c. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---