diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-16 16:35:52 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-16 16:35:52 +0100 |
commit | ca23287b448c2e007a5c93e43e762a10e0007b7a (patch) | |
tree | ff9bbd2f8e62d859b49d4afe6a3b552db648c804 | |
parent | ff594b2bc94ff2a942fe6ca05672387722dee686 (diff) | |
download | rails-ca23287b448c2e007a5c93e43e762a10e0007b7a.tar.gz rails-ca23287b448c2e007a5c93e43e762a10e0007b7a.tar.bz2 rails-ca23287b448c2e007a5c93e43e762a10e0007b7a.zip |
Revert "Added default_scope to Base [#1381 state:committed] (Paweł Kondzior)" -- won't gel with threads.
This reverts commit ff594b2bc94ff2a942fe6ca05672387722dee686.
-rw-r--r-- | activerecord/CHANGELOG | 16 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 10 | ||||
-rw-r--r-- | activerecord/test/cases/method_scoping_test.rb | 38 | ||||
-rw-r--r-- | activerecord/test/models/developer.rb | 12 |
4 files changed, 0 insertions, 76 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 84605b60ef..c2299b56ad 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,19 +1,3 @@ -*2.3.0/3.0* - -* Added default_scope to Base #1381 [Paweł Kondzior]. Example: - - class Person < ActiveRecord::Base - default_scope :order => 'last_name, first_name' - end - - class Company < ActiveRecord::Base - has_many :people - end - - Person.all # => Person.find(:all, :order => 'last_name, first_name') - Company.find(1).people # => Person.find(:all, :order => 'last_name, first_name', :conditions => { :company_id => 1 }) - - *2.2.1 [RC2] (November 14th, 2008)* * Ensure indices don't flip order in schema.rb #1266 [Jordi Bunster] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 9481c12b26..dcc8277849 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2016,16 +2016,6 @@ module ActiveRecord #:nodoc: @@subclasses[self] + extra = @@subclasses[self].inject([]) {|list, subclass| list + subclass.subclasses } end - # Sets the default options for the model. The format of the - # <tt>method_scoping</tt> argument is the same as in with_scope. - # - # class Person << ActiveRecord::Base - # default_scope :find => { :order => 'last_name, first_name' } - # end - def default_scope(options = {}) - self.scoped_methods << { :find => options, :create => options.is_a?(Hash) ? options[:conditions] : {} } - end - # Test whether the given method and optional key are scoped. def scoped?(method, key = nil) #:nodoc: if current_scoped_methods && (scope = current_scoped_methods[method]) diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index 79b24cd4fd..ff10bfaf3e 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -522,44 +522,6 @@ class HasAndBelongsToManyScopingTest< ActiveRecord::TestCase end -class DefaultScopingTest < ActiveRecord::TestCase - fixtures :developers - - def test_default_scope - expected = Developer.find(:all, :order => 'salary DESC').collect { |dev| dev.salary } - received = DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary } - assert_equal expected, received - end - - def test_method_scope - expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.salary } - received = DeveloperOrderedBySalary.all_ordered_by_name.collect { |dev| dev.salary } - assert_equal expected, received - end - - def test_nested_scope - expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.salary } - received = DeveloperOrderedBySalary.with_scope(:find => { :order => 'name DESC'}) do - DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary } - end - assert_equal expected, received - end - - def test_nested_exclusive_scope - expected = Developer.find(:all, :limit => 100).collect { |dev| dev.salary } - received = DeveloperOrderedBySalary.with_exclusive_scope(:find => { :limit => 100 }) do - DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary } - end - assert_equal expected, received - end - - def test_overwriting_default_scope - expected = Developer.find(:all, :order => 'salary').collect { |dev| dev.salary } - received = DeveloperOrderedBySalary.find(:all, :order => 'salary').collect { |dev| dev.salary } - assert_equal expected, received - end -end - =begin # We disabled the scoping for has_one and belongs_to as we can't think of a proper use case diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 1844014011..c08476f728 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -77,15 +77,3 @@ class DeveloperWithBeforeDestroyRaise < ActiveRecord::Base raise if projects.empty? end end - -class DeveloperOrderedBySalary < ActiveRecord::Base - self.table_name = 'developers' - default_scope :order => "salary DESC" - - def self.all_ordered_by_name - with_scope(:find => { :order => "name DESC" }) do - find(:all) - end - end - -end |