mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
updating documentation for named_scope and default_scope
This commit is contained in:
committed by
Xavier Noria
parent
06af291346
commit
198bffe3be
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user