【问题标题】:Navigating through relations for more than two level deep浏览超过两级深度的关系
【发布时间】:2013-03-01 16:53:06
【问题描述】:

从上到下,我的 table 之间有 belongs_to 关系,而从另一个方向来看 has_many。

ReportTarget
Report
Manager
Organization

我想对这些进行急切的加载。我想我可以走得这么深,但如果想要更深,我不知道语法,这是我需要的。我想从 Organization 一路走到 ReportTarget

@blah = Organization.includes([managers: :reports]).find(params[:id])

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.2 rails-activerecord eager-loading


    【解决方案1】:

    试试

    @blah = Organization.includes(managers: { reports: :report_targets }).find(params[:id])
    

    【讨论】:

    猜你喜欢
    • 2016-04-24
    • 1970-01-01
    • 2021-05-05
    • 1970-01-01
    • 2012-05-08
    • 2020-03-12
    • 1970-01-01
    • 2020-02-07
    • 1970-01-01
    相关资源
    最近更新 更多