Permalink
Browse files

decouple JoinAssociation from JoinDependency

  • Loading branch information...
1 parent bf8628d commit 84499eb4bd2e5fe686199c122194b72040411d04 @tenderlove tenderlove committed Oct 8, 2013
View
2 activerecord/lib/active_record/associations/join_dependency.rb
@@ -176,7 +176,7 @@ def build_join_association(reflection, parent, join_type)
raise EagerLoadPolymorphicError.new(reflection)
end
- JoinAssociation.new(reflection, self, parent, join_type)
+ JoinAssociation.new(reflection, join_parts.length, parent, join_type, alias_tracker)
end
def construct(parent, associations, join_parts, row, rs)
View
13 activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -9,11 +9,6 @@ class JoinAssociation < JoinPart # :nodoc:
# The reflection of the association represented
attr_reader :reflection
- # The JoinDependency object which this JoinAssociation exists within. This is mainly
- # relevant for generating aliases which do not conflict with other joins which are
- # part of the query.
- attr_reader :join_dependency
-
# A JoinBase instance representing the active record we are joining onto.
# (So in Author.has_many :posts, the Author would be that base record.)
attr_reader :parent
@@ -25,18 +20,18 @@ class JoinAssociation < JoinPart # :nodoc:
attr_reader :aliased_prefix
attr_reader :tables
+ attr_reader :alias_tracker
delegate :options, :through_reflection, :source_reflection, :chain, :to => :reflection
- delegate :alias_tracker, :to => :join_dependency
- def initialize(reflection, join_dependency, parent, join_type)
+ def initialize(reflection, index, parent, join_type, alias_tracker)
super(reflection.klass)
@reflection = reflection
- @join_dependency = join_dependency
+ @alias_tracker = alias_tracker
@parent = parent
@join_type = join_type
- @aliased_prefix = "t#{ join_dependency.join_parts.size }"
+ @aliased_prefix = "t#{ index }"
@tables = construct_tables.reverse
end

0 comments on commit 84499eb

Please sign in to comment.