updating documentation for named_scope and default_scope

This commit is contained in:
Neeraj Singh
2010-08-12 10:23:20 -04:00
committed by Xavier Noria
parent 06af291346
commit 198bffe3be
2 changed files with 19 additions and 0 deletions

View File

@@ -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

View File

@@ -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)