出于某种原因,当我在where
中使用时,会识别Date类scope :with_active_subthing, joins("left outer join thing_subthing on thing_subthing.patient_id = thing.id").where("thing_subthing.start_date <= ? AND ( thing_subthing.end_date > ? OR thing_subthing.end_date IS NULL ) ", Date.today, Date.today)
但在联接中使用它时无法识别
scope :with_active_subthing, joins("left outer join thing_subthing on thing_subthing.patient_id = thing.id AND (thing_subthing.start_date <= ? AND ( thing_subthing.end_date > ? OR thing_subthing.end_date IS NULL )) ", Date.today, Date.today)
我明白了:
RuntimeError: unknown class: Date
答案 0 :(得分:3)
如果查看underlying code that builds the join portion,您可以看到它正在查找特定的对象类型,而Date不是其中之一。这个错误有点令人困惑,但它的含义是Date不能用作joins
的参数。你的问题并不是很清楚你为什么要这样做,但是你应该绝对使用两个联接和你在第一个例子中一起使用的地方。
这是造成问题的代码,因为它正在落到“加注”行:
def build_joins(manager, joins)
buckets = joins.group_by do |join|
case join
when String
'string_join'
when Hash, Symbol, Array
'association_join'
when ActiveRecord::Associations::JoinDependency::JoinAssociation
'stashed_join'
when Arel::Nodes::Join
'join_node'
else
raise 'unknown class: %s' % join.class.name
end
end