ActiveRecord Association Through that has many foreign_key in Joins table -
below example
teacher has_many students student has_many teachers student has_many books book has_many colors
class teacher < applicationrecord has_many :meetings has_many :books, through: :meetings end class student < applicationrecord has_many :meetings has_many :teachers, through: :meetings end class book < applicationrecord has_many :meetings has_many :colors, through: :meetings end class meeting < applicationrecord belongs_to :teacher belongs_to :student belongs_to :book belongs_to :color end
i have problem result shows on index page not right.
for example:
@teacher.name @teacher.students.each |s| s.name s.books.each |b| book.name b.colors.each |c| c.name end end end
please help!
thanks,
helen ta.
Comments
Post a Comment