aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/active_record_querying.textile
diff options
context:
space:
mode:
authorJosé Corcuera <jzcorcuera@gmail.com>2012-09-07 10:24:24 -0500
committerJosé Corcuera <jzcorcuera@gmail.com>2012-09-07 10:24:24 -0500
commit4d33481e1b142e65f27a57fba859e4fb6bdf46c0 (patch)
treee4ece9fd66f404ef3287c666db0c609621f6b0a3 /guides/source/active_record_querying.textile
parentfce0d088a591d7254fcda8e45683a43eff508957 (diff)
downloadrails-4d33481e1b142e65f27a57fba859e4fb6bdf46c0.tar.gz
rails-4d33481e1b142e65f27a57fba859e4fb6bdf46c0.tar.bz2
rails-4d33481e1b142e65f27a57fba859e4fb6bdf46c0.zip
How to use default_scope as a class method
Diffstat (limited to 'guides/source/active_record_querying.textile')
-rw-r--r--guides/source/active_record_querying.textile10
1 files changed, 10 insertions, 0 deletions
diff --git a/guides/source/active_record_querying.textile b/guides/source/active_record_querying.textile
index e211466339..671253709a 100644
--- a/guides/source/active_record_querying.textile
+++ b/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
</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.