【问题标题】:active record joins with distinct record活动记录与不同记录连接
【发布时间】:2018-08-17 11:15:36
【问题描述】:

我有一个带有多个时隙的事件模型(属性都为日期时间)

我需要根据通过连接应用于时隙模型的某些条件获取不同的事件,并按某种顺序排序。

我尝试了一些方法,但是当我在事件属性上而不是在时隙属性上排序时,它才有效。

Event.joins(:time_slots).order('time_slots.from asc').distinct 

抛出 InvalidColumnReference 错误

Event.joins(:time_slots).order('events.id asc').distinct

作品

我怎样才能使以前的查询工作?

【问题讨论】:

    标签: ruby ruby-on-rails-5


    【解决方案1】:

    我不得不使用Event.includes 而不是Event.joins,它实际上按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-17
      • 1970-01-01
      • 1970-01-01
      • 2014-06-22
      • 1970-01-01
      • 2013-08-02
      相关资源
      最近更新 更多