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

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -