我的Program
班级 has_manyPatients
和Patient
班级有一个像salary
我传递给 JBuilder 的 jsonrespond_to :json , respond_with(@org)
是这样的:
@org = Org.includes(programs: [{hospitals: :nurses}, :patients]).find(params[:id])
现在,如果我的数据库有 200 个满足org_id = params[:id]
条件的程序,它将全部返回。但这不是我想要的。我想告诉它返回“5”个程序和那些“5”个程序,他们的“患者”表的“薪水”字段是最高的。
如何在活动记录查询中实现此限制?