【问题标题】:Rails : scope for has_many associationRails:has_many 关联的范围
【发布时间】:2015-01-15 21:12:25
【问题描述】:

我有 2 个模型 Person 和 PersonInterest : 人包含关于一个人的所有信息 Person Interests 存储一个人的兴趣(person_id,interest_id)

Person has_many PersonInterests

如何创建一个可以搜索所有具有相同interest_id 的人的范围

【问题讨论】:

    标签: ruby-on-rails search named-scopes


    【解决方案1】:

    我自己想出来的。你需要像这样创建一个连接:

    Person.joins(person_interests).where(:person_interests => {interest_id = 1})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多