I have a 3 table – users, employees, contacts.
The employees and contacts have a foreign key pointing the the associated user.
Employee belongs_to :user
Contact belongs_to :user
User has many employees, contacts
But, I would like to list the employee name or contact name in the user index view.
Do I need to use a find_by_sql statement?
Thanks,
Dave
You have the
belongs_toassociations set up already, so you can add thehas_oneassociation in your User class for employee and contact, then you can do@user.employee.nameor@user.contact.name.You definitely don’t need
find_by_sqlfor this.