我需要在 Mongoid 中创建一个命名范围,用于比较同一文档中的两个时间字段。如
scope :foo, :where => {:updated_at.gt => :checked_at}
这显然不起作用,因为它被视为:checked_at
一个符号,而不是实际的字段。关于如何做到这一点的任何建议?
更新 1
这是我声明了这个范围的模型,去掉了很多额外的代码。
class User
include Mongoid::Document
include Mongoid::Paranoia
include Mongoid::Timestamps
field :checked_at, :type => Time
scope :unresolved, :where => { :updated_at.gt => self.checked_at }
end
这给了我以下错误:
'<class:User>': undefined method 'checked_at' for User:Class (NoMethodError)