Jes*_*ess 19 ruby-on-rails models default-scope
在我的Post.rb模型中,我有 default_scope :conditions => {:deleted => 'false'}
但如果我试图跑Post.find(:all, :conditions => "deleted='false'"),它将不会返回任何东西.就像default_scope优先于所有内容一样.
我想要它,以便当我这样做Post.find()时不会返回已删除的帖子,但我也希望能够在需要时访问它们.在我的查询或我的Rails模型中需要更改什么?
谢谢.
小智 17
with_exclusive_scope是的protected,所以你必须创建一个类方法:
def self.include_deleted_in
Event.with_exclusive_scope { yield }
end
Run Code Online (Sandbox Code Playgroud)
然后在你的控制器调用
Post.include_deleted_in { Post.find(:all) }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8237 次 |
| 最近记录: |