开发者

Dirty object with named scope?

开发者 https://www.devze.com 2023-03-09 03:22 出处:网络
How to use dirty object with named scope ? This named_scope is working fine. named_scope :recently_tested, lambda{|test_id|

How to use dirty object with named scope ?

This named_scope is working fine.

 named_scope :recently_tested, lambda{|test_id|
    {
      :conditions =>  ["test_id = ? and status = ?",test_id,PUBLISHED],
      :order => "updated_at DESC"
    }
  }

I want to enhance it. Something like

 named_scope :recently_tested, lambda{|test_id|
    开发者_开发百科{
      :conditions =>  ["test_id = ? and status = ? and status_was = ?",test_id,PUBLISHED,PUBLISHED],
      :order => "updated_at DESC"
    }
  }

Is it possible to use dirty object with named_scope ? Any other ways to handle this scenario ?


The change helper function status_was isn't actually a field in your database.

Upon changing an object, changes, changed? and other helpers like your status_was only remain until you save the object.

If you want this to persist, you'll have to add the status_was field to your model and simply populate it in a before_save for example. I wouldn't call it status_was though, because you'd be overwriting the helper function.

0

精彩评论

暂无评论...
验证码 换一张
取 消