上から下まで、私はテーブル間に属している関係を持ち、他の方向からはよく has_many を持っています。
ReportTarget
Report
Manager
Organization
と
Score
Manager
Organization
Report
テーブルとScore
テーブルが同じレベルにあることに注意してください。どちらもManager
テーブルを親として持っています。
個人的には、熱心な読み込みでそれらをナビゲートする方法を理解できました。最初に私がやります:
@blah = Organization.includes(managers: { reports: :report_targets }).find(params[:id])
2番目のものについては、これを行うことができます:
@blah = Organization.includes([managers: :scores]).find(params[:id])
しかし、コントローラーで処理していて、JSON を JBuilder に渡したいので、両方を渡す方法がわかりません。それともそれらを組み合わせますか?結果のハッシュはそれらを1つのハッシュにしますが、別々のキーを持ちます:
{
"firstoneinfo" : [
# stuff that first json returns, can have their own internal hashes
],
"SecondOneinfo : [
#stuff that second json returns, can have their own internal hashes
]
}