@companies = this has lets say 3 but is dynamic in range
@companies.each do |c|
workers = current_user.workers.find_by_company_id(c.id)
end
在所有这些结束时,我希望工人就像它是一个查询的结果。但在这种情况下,对象必须是 3 个查询的组合。
可能?
这个?
workers = current_user.workers.where(:company_id => @companies.map(&:id))
Rails 会自动为您映射 id:
current_user.workers.find_all_by_company_id(@companies)