我需要在Mongoid中创建一个命名范围,该范围比较同一文档中的两个时间字段。如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)
太棒了,这个作品很棒。也感谢您的性能建议。 – 2010-10-18 05:54:01