I am trying to figure out how to create ActiveRecord models with associations that can produce 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 structure of the table is as follows and assumes that each table has an id for the usual ActiveRecord convention:
bills
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 models to be fully functional and not limited to things like : find_by_sql .
How to create related models that make this possible?
Thanks!
Chris Benson
chris@chrisbenson.com
Chris source share