I have 3 models: User, School, and Applicant.
A user has_many :schools, a school has_many :applicants and belongs_to :user, and an applicant belongs_to :school.
I’d like to be able to list applicants that belong to any school that belongs to a particular user. I thought I should be able to do it with
current_user.schools.applicants.paginate(page: params[:page])
That is not working as it is giving this error:
undefined method `applicants' for #<ActiveRecord::Relation:0x007fb9da274110>
How can I access these applicants?
You cannot chain
has_manyassociations like that. Create ahas_many :throughassociation on the user model:Then you can call
From the guide on ActiveRecord associations: