I have a User class that is associated with Contact through UserContact. class User has_many :user_contacts has_many :contacts, :through => :user_contacts, :source => :contact, :order => ''contacts.last_name ASC'' end UserContact defines a many-to-many relationship with attributes. The problem I have is how to best access the attributes in UserContact without constantly accessing the database. For example: contacts = user.contacts contacts.each do |contact| # Do stuff with contact # How do I access the UserContact instance that through used to access the contact? end I could do uc = user.user_contacts.find_by_contact_id(contact.id) but that results in another database call for each contact. I suppose I could do something like: user_contacts = user.user_contacts.find(:all, :include => :contact, :order => ''contacts.last_name ASC'') user_contacts.each do |uc| puts uc.contact.last_name puts uc.attribute_name end I was hoping there might be another way to work :through backwards from the target. The above will work, but it is not as clean as the :through relationship. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---