I have 3 models set up like this:
Trip
has_many :workgroups, through: :invitations
Workgroup
has_many :trips, through: :invitations
has_many :employees
Employee
belongs_to :workgroup
Employees are nested in workgroups.
I am trying to access employee data in the trip views. Currently, I get the following error: undefined method 'employees'
Can I access the employee data from the trip model without creating a direct association between the two models?
There is no way to directly reference the employee data from the trip model without creating an association.
You can either add a has_many through relationship, or reference it something like this (I’m just making a guess based on your code above.)
trip.workgroups.first.employeesIf you want to be able to view all ‘students’ associated in a workgroup that is associated to a trip, you’ll have to add the association.
I think that you should be able to do this: