diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-06-28 14:41:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-28 14:41:59 -0400 |
commit | 33de72667a026f8a9c188189bcc191976a7c397a (patch) | |
tree | c3f33e633acb9f8caa2c2cf06f966ab89e3952b7 /activerecord | |
parent | f94b2e850330ae9b69c874d1fad8a4a38d736d36 (diff) | |
parent | eacec5defe89dd9593d44f4831aa861a2e0e55d4 (diff) | |
download | rails-33de72667a026f8a9c188189bcc191976a7c397a.tar.gz rails-33de72667a026f8a9c188189bcc191976a7c397a.tar.bz2 rails-33de72667a026f8a9c188189bcc191976a7c397a.zip |
Merge pull request #29610 from kamipo/dont_passing_klass_connection_to_association_scope
Don't passing `klass.connection` to `AssociationScope`
Diffstat (limited to 'activerecord')
5 files changed, 8 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 5c45187d8f..44cf1f8915 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -94,7 +94,7 @@ module ActiveRecord # actually gets built. def association_scope if klass - @association_scope ||= AssociationScope.scope(self, klass.connection) + @association_scope ||= AssociationScope.scope(self) end end diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index 1744dc785f..6ef225b725 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -1,8 +1,8 @@ module ActiveRecord module Associations class AssociationScope #:nodoc: - def self.scope(association, connection) - INSTANCE.scope(association, connection) + def self.scope(association) + INSTANCE.scope(association) end def self.create(&block) @@ -16,12 +16,12 @@ module ActiveRecord INSTANCE = create - def scope(association, connection) + def scope(association) klass = association.klass reflection = association.reflection scope = klass.unscoped owner = association.owner - alias_tracker = AliasTracker.create connection, association.klass.table_name + alias_tracker = AliasTracker.create(klass.connection, klass.table_name) chain_head, chain_tail = get_chain(reflection, association, alias_tracker) scope.extending! reflection.extensions diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 583ee11907..bbf3dbb75e 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -304,7 +304,7 @@ module ActiveRecord sc = reflection.association_scope_cache(conn, owner) do StatementCache.create(conn) { |params| as = AssociationScope.create { params.bind } - target_scope.merge as.scope(self, conn) + target_scope.merge!(as.scope(self)) } end diff --git a/activerecord/lib/active_record/associations/singular_association.rb b/activerecord/lib/active_record/associations/singular_association.rb index 2b426da607..f8bbe4c2ed 100644 --- a/activerecord/lib/active_record/associations/singular_association.rb +++ b/activerecord/lib/active_record/associations/singular_association.rb @@ -43,7 +43,7 @@ module ActiveRecord sc = reflection.association_scope_cache(conn, owner) do StatementCache.create(conn) { |params| as = AssociationScope.create { params.bind } - target_scope.merge(as.scope(self, conn)).limit(1) + target_scope.merge!(as.scope(self)).limit(1) } end diff --git a/activerecord/test/cases/associations/association_scope_test.rb b/activerecord/test/cases/associations/association_scope_test.rb index c322333f6d..c54542ff7b 100644 --- a/activerecord/test/cases/associations/association_scope_test.rb +++ b/activerecord/test/cases/associations/association_scope_test.rb @@ -6,8 +6,7 @@ module ActiveRecord module Associations class AssociationScopeTest < ActiveRecord::TestCase test "does not duplicate conditions" do - scope = AssociationScope.scope(Author.new.association(:welcome_posts), - Author.connection) + scope = AssociationScope.scope(Author.new.association(:welcome_posts)) binds = scope.where_clause.binds.map(&:value) assert_equal binds.uniq, binds end |