Permalink
Browse files

decouple the manager class from building join constraints

  • Loading branch information...
tenderlove committed Jul 16, 2013
1 parent 743b675 commit 85fe5edcec77f96923ed4f4e8b63a247ebe6b055
@@ -64,7 +64,8 @@ def find_parent_in(other_join_dependency)
end
end
- def join_to(manager)
+ def join_constraints
+ joins = []
tables = @tables.dup
foreign_table = parent_table
@@ -84,11 +85,10 @@ def join_to(manager)
foreign_key = reflection.foreign_key
when :has_and_belongs_to_many
# Join the join table first...
- manager.from(join(
+ joins << join(
table,
table[reflection.foreign_key].
- eq(foreign_table[reflection.active_record_primary_key])
- ))
+ eq(foreign_table[reflection.active_record_primary_key]))
foreign_table, table = table, tables.shift
@@ -125,13 +125,13 @@ def join_to(manager)
constraint = constraint.and rel.arel.constraints
end
- manager.from(join(table, constraint))
+ joins << join(table, constraint)
# The current table in this iteration becomes the foreign table in the next
foreign_table, foreign_klass = table, klass
end
- manager
+ joins
end
# Builds equality condition.
@@ -948,10 +948,11 @@ def build_joins(manager, joins)
join_dependency.graft(*stashed_association_joins)
- # FIXME: refactor this to build an AST
- join_dependency.join_associations.each do |association|
- association.join_to(manager)
- end
+ joins = join_dependency.join_associations.map { |association|
+ association.join_constraints
+ }.flatten
+
+ joins.each { |join| manager.from join }
manager.join_sources.concat join_list

0 comments on commit 85fe5ed

Please sign in to comment.