提交 8e6ef92f 编写于 作者: A Aaron Patterson

pass the association and connection to the scope method

上级 3b675f05
......@@ -94,7 +94,7 @@ def scope
# actually gets built.
def association_scope
if klass
@association_scope ||= AssociationScope.new(self).scope
@association_scope ||= AssociationScope.new.scope(self, klass.connection)
end
end
......
module ActiveRecord
module Associations
class AssociationScope #:nodoc:
attr_reader :association
def initialize(association)
@association = association
end
def scope
def scope(association, connection)
klass = association.klass
reflection = association.reflection
scope = klass.unscoped
owner = association.owner
alias_tracker = AliasTracker.new klass.connection
alias_tracker = AliasTracker.new connection
scope.extending! Array(reflection.options[:extend])
add_constraints(scope, owner, klass, reflection, alias_tracker)
......
......@@ -6,8 +6,10 @@ module ActiveRecord
module Associations
class AssociationScopeTest < ActiveRecord::TestCase
test 'does not duplicate conditions' do
association_scope = AssociationScope.new(Author.new.association(:welcome_posts))
wheres = association_scope.scope.where_values.map(&:right)
association_scope = AssociationScope.new
scope = association_scope.scope(Author.new.association(:welcome_posts),
Author.connection)
wheres = scope.where_values.map(&:right)
assert_equal wheres.uniq, wheres
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册