Chris Benson
2010-Mar-05 18:58 UTC
How to create Rails models w/ multiple complex associations?
I am trying to figure out how to create ActiveRecord models with associations that can yield the same results as this SQL query: select login, first_name, last_name, email_address from accounts inner join people on person.id = accounts.person_id inner join email_address_people on person.id = email_address_people.person_id inner join email_addresses on email_address.id email_address_people.email_address_id inner join email_address_types on email_address_types.id = email_address_people.email_address_type_id where email_address_types.email_address_type = ''account''; The table structure is as follows, and assumes each table has an id per normal ActiveRecord convention: accounts id : int person_id : int login : string people id : int first_name : string last_name : string email_address_people id : int person_id : int email_address_id : int email_address_type_id : int email_addresses id : int email_address : string email_address_types id : int email_address_type: string I need the models to be fully functional, and not limited by things like :find_by_sql. How do I create the associated models that make this possible? Thanks! Chris Benson chris-FWmUuopPHSpXqviUI+FSNg@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.