activerecord - Retrieve records from multiple levels of has_many relationships in Rails -
organization has many project. project has many websites. how websites particular organization rails 4?
you can retrieve websites using:
@websites = website.includes(:project => :organizations).where(["organization.id = ?", params[:organization]])
make sure params[:organization]
actual id of organization of want fetch websites for.
you can use has_many :through association. way, able websites simple @organization.websites
.
a has_many :through association used set many-to-many connection model. association indicates declaring model can matched 0 or more instances of model proceeding through third model. example, consider medical practice patients make appointments see physicians. relevant association declarations this:
Comments
Post a Comment