【问题标题】:How to get data from multiple tables in Ruby on Rails?如何从 Ruby on Rails 中的多个表中获取数据?
【发布时间】:2013-09-06 19:53:14
【问题描述】:

我有桌子:

table specs
column: profession_id
column: id

table prof
column: id

我已成功收到来自单个教授的数据并列出了它的孩子(规格)

Profession.joins(:specializations).find_by_slug(params[:id])

但现在我还有两张桌子:

table docs
column: id

table docs_specs
column: docs_id
column: specs_id

因此,表格文档和规范是相互关联的。 我怎样才能获得单个教授,它的子规格(已经工作)和每个规格的“文档”子级。有点复杂吧?

【问题讨论】:

    标签: mysql ruby-on-rails ruby join


    【解决方案1】:

    你可以这样做:

    Profession.where(:id >= params[:id]).joins(:specs => {:docs_specs => :docs})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 2014-05-03
      • 1970-01-01
      • 2020-03-17
      • 1970-01-01
      • 2016-11-29
      • 1970-01-01
      相关资源
      最近更新 更多