Yes, there is a more elegant way to do this. You can look forward to downloading the results. Let me show you.
without filtering the list of faces
person = Person.find(10).includes(:projects=>:tasks)
This will load the results, so if you call person.projects.first.tasks.first , it has already been downloaded, and more sql queries will fail.
If you want to filter them out, follow these steps:
person = Person.where('people.id=10 AND projects.duration < ?', x).includes(:projects=>:tasks)
If you want to iterate over only all tasks without iterating over projects, you should establish a relationship such as:
class Person has_many :projects has_many :tasks, :through=>:projects end
To repeat them, do the following:
person = Person.find(10) person.tasks.where('projects.duration < ?', x)
source share