ruby on rails - Mongoid named scope comparing two time fields in the same document -
i need create named scope in mongoid compares 2 time fields within same document. such as
scope :foo, :where => {:updated_at.gt => :checked_at}
this won't work treats :checked_at
symbol, not actual field. suggestions on how can done?
update 1
here model have scope declared, lot of code stripped out.
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
this gives me following error:
'<class:user>': undefined method 'checked_at' user:class (nomethoderror)
as far know, mongodb doesn't support queries against dynamic values. use javascript function:
scope :unresolved, :where => 'this.updated_at >= this.checked_at'
to speed add attribute "is_unresolved" set true on update when condition matched ( , index ).
Comments
Post a Comment