Suppose I have a one-to-many association
in the Author class
has_many :books
in the School class
has_many :books
in the Book class
belongs_to :authors
belongs_to :schools
Now hitting the SchoolsController#some_method, with params[:id] as a get request parameter, I want to retrieve all the authors of books that are in some param[:id] school. So I wrote this that works
@shools = Books.where(school_id: params[:id])
@books ||= []
@books.each do |book|
@books << book.user
end
but I don't think it is the correct rails way to do that. Could someone help ?