Permalink
Browse files

updating documentation for named_scope and default_scope

  • Loading branch information...
1 parent 06af291 commit 198bffe3be42d54932e8458b4d8fd2cbb2a5eb09 Neeraj Singh committed with fxn Aug 12, 2010
Showing with 19 additions and 0 deletions.
  1. +10 −0 activerecord/lib/active_record/base.rb
  2. +9 −0 activerecord/lib/active_record/named_scope.rb
@@ -1147,6 +1147,16 @@ def with_exclusive_scope(method_scoping = {}, &block)
# 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
@@ -88,6 +88,15 @@ def scopes
# 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)

0 comments on commit 198bffe

Please sign in to comment.