I have some nested models that look something like:
class Company
has_many :managers
end
class Manager
has_many :employees
end
class Employee
has_many :tasks
end
class Task
end
So that’s all fine but what if I’m in the Company controller and I want to get all the Task.ids for all of the employees in that company? The big problem is that Mongoid doesn’t have like has_many :through => resource_name like AR does so how can I avoid something ugly like:
@company = Company.find params[:id]
@company.managers.each do |manager|
manager.employees.each do |employee|
employee.tasks.each do |task|
puts task.id
end
end
end
Perhaps there’s a Rails way to do this that I don’t know, but you could just use some simple Ruby trickery: