Browse files

Extract JoinDependency#join_relation to DRY the repeated application …

…of the #join_associations.
  • Loading branch information...
1 parent 35c198c commit fba18f19948f084023fd8744025f57da00163265 @Empact Empact committed May 10, 2013
View
7 activerecord/lib/active_record/associations/join_dependency.rb
@@ -55,6 +55,13 @@ def join_base
join_parts.first
end
+ def join_relation(relation)
+ join_associations.each do |association|
+ relation = association.join_relation(relation)
+ end
+ relation
+ end
+
def columns
join_parts.collect { |join_part|
table = join_part.aliased_table
View
5 activerecord/lib/active_record/relation/finder_methods.rb
@@ -225,10 +225,7 @@ def construct_relation_for_association_find(join_dependency)
def apply_join_dependency(relation, join_dependency)
relation = relation.except(:includes, :eager_load, :preload)
-
- join_dependency.join_associations.each do |association|
- relation = association.join_relation(relation)
- end
+ relation = join_dependency.join_relation(relation)
if using_limitable_reflections?(join_dependency.reflections)
relation
View
4 activerecord/lib/active_record/relation/merger.rb
@@ -94,9 +94,7 @@ def merge_joins
[])
relation.joins! rest
- join_dependency.join_associations.each do |association|
- @relation = association.join_relation(relation)
- end
+ @relation = join_dependency.join_relation(relation)
end
end

0 comments on commit fba18f1

Please sign in to comment.