diff options
Diffstat (limited to 'activerecord')
6 files changed, 16 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 6eda70d0ce..5ecdf1ac8d 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -405,6 +405,9 @@ module ActiveRecord else super end + elsif @reflection.klass.scopes[method] + @_scopes ||= {} + @_scopes[method] ||= with_scope(construct_scope) { @reflection.klass.send(method, *args) } else with_scope(construct_scope) do if block_given? diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 5f741c6ae7..f0b107255c 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -11,7 +11,7 @@ require 'active_support/core_ext/hash/deep_merge' require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/string/behavior' -require 'active_support/core_ext/object/singleton_class' +require 'active_support/core_ext/kernel/singleton_class' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/object/duplicable' require 'active_support/core_ext/object/blank' diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 86ba7d72c3..6d4ab501fa 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -291,7 +291,7 @@ module ActiveRecord # Remove the index named by_branch_party in the accounts table. # remove_index :accounts, :name => :by_branch_party def remove_index(table_name, options = {}) - execute "DROP INDEX #{quote_column_name(index_name(table_name, options))} ON #{table_name}" + execute "DROP INDEX #{quote_column_name(index_name(table_name, options))} ON #{quote_table_name(table_name)}" end def index_name(table_name, options) #:nodoc: diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index d4cda927ad..c163fb982a 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -1,4 +1,4 @@ -require 'active_support/core_ext/object/singleton_class' +require 'active_support/core_ext/kernel/singleton_class' module ActiveRecord # Exception that can be raised to stop migrations from going backwards. diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb index 632322b517..aeed52e72a 100644 --- a/activerecord/lib/active_record/named_scope.rb +++ b/activerecord/lib/active_record/named_scope.rb @@ -1,6 +1,6 @@ require 'active_support/core_ext/array' require 'active_support/core_ext/hash/except' -require 'active_support/core_ext/object/singleton_class' +require 'active_support/core_ext/kernel/singleton_class' require 'active_support/core_ext/object/blank' module ActiveRecord diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 2396ca10b0..3d5ebb6cb8 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -413,6 +413,15 @@ class NamedScopeTest < ActiveRecord::TestCase Topic.approved.by_lifo.replied.written_before(Time.now).all end end + + def test_named_scopes_are_cached_on_associations + post = posts(:welcome) + + assert_equal post.comments.containing_the_letter_e.object_id, post.comments.containing_the_letter_e.object_id + + post.comments.containing_the_letter_e.all # force load + assert_no_queries { post.comments.containing_the_letter_e.all } + end end class DynamicScopeMatchTest < ActiveRecord::TestCase |