Browse files

How to use default_scope as a class method

  • Loading branch information...
1 parent fce0d08 commit 4d33481e1b142e65f27a57fba859e4fb6bdf46c0 @jcorcuera jcorcuera committed Sep 7, 2012
Showing with 10 additions and 0 deletions.
  1. +10 −0 guides/source/active_record_querying.textile
@@ -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
+If you need to do more complex things with a default scope, you can alternatively define it as a class method:
+class Client < ActiveRecord::Base
+ def self.default_scope
+ # Should return a scope
+ end
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.

0 comments on commit 4d33481

Please sign in to comment.