从上到下,我的表之间有 belongs_to 关系,而从另一个方向来看,还有 has_many 关系。
ReportTarget
Report
Manager
Organization
和
Score
Manager
Organization
所以请注意Report
table 和Score
table 在同一级别上。他们都有Manager
Table 作为他们的父母。
我个人可以弄清楚如何通过急切加载来导航它们。对于第一个我会做:
@blah = Organization.includes(managers: { reports: :report_targets }).find(params[:id])
对于第二个,我可以这样做:
@blah = Organization.includes([managers: :scores]).find(params[:id])
但是因为我在我的控制器中使用并想将 JSON 传递给 JBuilder,所以我不知道如何传递它们?或者也许将它们结合在一起?这样生成的散列将它们放在一个散列中,但具有单独的键:
{
"firstoneinfo" : [
# stuff that first json returns, can have their own internal hashes
],
"SecondOneinfo : [
#stuff that second json returns, can have their own internal hashes
]
}