码迷,mamicode.com
首页 > 其他好文 > 详细

4种scope方法

时间:2015-02-03 17:07:24      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

默认作用域,自动加载:

default_scope { order(created_at: :desc) }

 

model 调用 find_2时才运行

scope :find_2, ->{ where(‘clients.id‘ => 2 ) }

 

下面都需要传参,使用model.find_2(id)调用

scope :find_2, ->(id) { where(‘clients.id‘ => id) }

scope :find_2, lambda { |id| where(‘clients.id‘ => id) }

4种scope方法

标签:

原文地址:http://www.cnblogs.com/tardis/p/4270269.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!