diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-08-12 10:23:20 -0400 |
---|---|---|
committer | Neeraj Singh <neerajdotname@gmail.com> | 2010-08-12 10:23:20 -0400 |
commit | cfad74cfef51888321c042623c9e2fb9663640f3 (patch) | |
tree | 7044d960516382c22b6d3da799c23ddb1df63a5e /activerecord/lib | |
parent | a6c6cbfb552102eb974a45e25d21372ed62891b8 (diff) | |
download | rails-cfad74cfef51888321c042623c9e2fb9663640f3.tar.gz rails-cfad74cfef51888321c042623c9e2fb9663640f3.tar.bz2 rails-cfad74cfef51888321c042623c9e2fb9663640f3.zip |
updating documentation for named_scope and default_scope
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/base.rb | 10 | ||||
-rw-r--r-- | activerecord/lib/active_record/named_scope.rb | 9 |
2 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 8da4fbcba7..a464b65c19 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1147,6 +1147,16 @@ MSG # class Person < ActiveRecord::Base # default_scope order('last_name, first_name') # end + # + # <tt>default_scope</tt> is also applied while creating/building a record. It is not + # applied while updating a record. + # + # class Article < ActiveRecord::Base + # default_scope where(:published => true) + # end + # + # Article.new.published #=> true + # Article.create.published #=> true def default_scope(options = {}) self.default_scoping << construct_finder_arel(options, default_scoping.pop) end diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb index 0e560418dc..c95060126e 100644 --- a/activerecord/lib/active_record/named_scope.rb +++ b/activerecord/lib/active_record/named_scope.rb @@ -88,6 +88,15 @@ module ActiveRecord # end # end # end + # + # Scopes can also be used while creating/building a record. + # + # class Article < ActiveRecord::Base + # scope :published, where(:published => true) + # end + # + # Article.published.new.published #=> true + # Article.published.create.published #=> true def scope(name, scope_options = {}, &block) name = name.to_sym valid_scope_name?(name) |