diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-18 04:38:19 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-18 04:38:19 +0530 |
commit | d60bb0a9e4be2ac0a9de9a69041a4ddc2e0cc914 (patch) | |
tree | 0189bf9fe9888963df51987e5e330b09e2e19b59 /activerecord/lib/active_record | |
parent | e1d507c7fb541d29d57d152f40e3a539e70781d0 (diff) | |
download | rails-d60bb0a9e4be2ac0a9de9a69041a4ddc2e0cc914.tar.gz rails-d60bb0a9e4be2ac0a9de9a69041a4ddc2e0cc914.tar.bz2 rails-d60bb0a9e4be2ac0a9de9a69041a4ddc2e0cc914.zip |
Rename named_scope to scope
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/named_scope.rb | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb index 16fde1ffb8..42fc6c5f28 100644 --- a/activerecord/lib/active_record/named_scope.rb +++ b/activerecord/lib/active_record/named_scope.rb @@ -38,11 +38,11 @@ module ActiveRecord # such as <tt>:conditions => {:color => :red}, :select => 'shirts.*', :include => :washing_instructions</tt>. # # class Shirt < ActiveRecord::Base - # named_scope :red, :conditions => {:color => 'red'} - # named_scope :dry_clean_only, :joins => :washing_instructions, :conditions => ['washing_instructions.dry_clean_only = ?', true] + # scope :red, :conditions => {:color => 'red'} + # scope :dry_clean_only, :joins => :washing_instructions, :conditions => ['washing_instructions.dry_clean_only = ?', true] # end # - # The above calls to <tt>named_scope</tt> define class methods Shirt.red and Shirt.dry_clean_only. Shirt.red, + # The above calls to <tt>scope</tt> define class methods Shirt.red and Shirt.dry_clean_only. Shirt.red, # in effect, represents the query <tt>Shirt.find(:all, :conditions => {:color => 'red'})</tt>. # # Unlike <tt>Shirt.find(...)</tt>, however, the object returned by Shirt.red is not an Array; it resembles the association object @@ -68,7 +68,7 @@ module ActiveRecord # Named \scopes can also be procedural: # # class Shirt < ActiveRecord::Base - # named_scope :colored, lambda { |color| + # scope :colored, lambda { |color| # { :conditions => { :color => color } } # } # end @@ -78,7 +78,7 @@ module ActiveRecord # Named \scopes can also have extensions, just as with <tt>has_many</tt> declarations: # # class Shirt < ActiveRecord::Base - # named_scope :red, :conditions => {:color => 'red'} do + # scope :red, :conditions => {:color => 'red'} do # def dom_id # 'red_shirts' # end @@ -90,14 +90,14 @@ module ActiveRecord # <tt>proxy_options</tt> method on the proxy itself. # # class Shirt < ActiveRecord::Base - # named_scope :colored, lambda { |color| + # scope :colored, lambda { |color| # { :conditions => { :color => color } } # } # end # # expected_options = { :conditions => { :colored => 'red' } } # assert_equal expected_options, Shirt.colored('red').proxy_options - def named_scope(name, options = {}, &block) + def scope(name, options = {}, &block) name = name.to_sym if !scopes[name] && respond_to?(name, true) @@ -118,6 +118,11 @@ module ActiveRecord end end end + + def named_scope(*args, &block) + ActiveSupport::Deprecation.warn("Base#named_scope has been deprecated, please use Base.scope instead.", caller) + scope(*args, &block) + end end class Scope < Relation |