提交 4d33481e 编写于 作者: J José Corcuera

How to use default_scope as a class method

上级 fce0d088
......@@ -1158,6 +1158,16 @@ When queries are executed on this model, the SQL query will now look something l
SELECT * FROM clients WHERE removed_at IS NULL
</sql>
If you need to do more complex things with a default scope, you can alternatively define it as a class method:
<ruby>
class Client < ActiveRecord::Base
def self.default_scope
# Should return a scope
end
end
</ruby>
h4. Removing all scoping
If we wish to remove scoping for any reason we can use the +unscoped+ method. This is especially useful if a +default_scope+ is specified in the model and should not be applied for this particular query.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册