不妨直接告诉聪明的find_incomplete方法:
@tasks = Task.find_incomplete :limit => 20然后在方法定义中使用with_scope:
def self.find_incomplete(options => {})当然,如果不用with_scope,或者还想传order条件(上面order是写死了的),可以merge options:
with_scope :find => options do
find_all_by_complete(false, :order => 'created_at DESC')
end
end
def self.find_incomplete(options => {})或者使用reverse_merge:
find_all_by_complete(false, (:order => 'created_at DESC').merge(options))
end
find_all_by_complete(false, options.reverse_merge(:order => 'created_at DESC'))
在关联查询里,也可以传options进去:
@tasks = @project.tasks.find_incomplete :limit => 20这里的task查询在两个scope里,一个是@project限定的scope,第二个是:limit限定的scope
没有评论:
发表评论