Skip to content
Browse files

DRY-up join dependency creation by extracting construct_join_depdency

  • Loading branch information...
1 parent 88219cc commit 75fe7434a81d0aaef8ec2ada8f88b5b20721c25a @Empact Empact committed May 10, 2013
Showing with 5 additions and 7 deletions.
  1. +5 −7 activerecord/lib/active_record/relation/finder_methods.rb
View
12 activerecord/lib/active_record/relation/finder_methods.rb
@@ -160,7 +160,7 @@ def exists?(conditions = :none)
conditions = conditions.id if Base === conditions
return false if !conditions
- join_dependency = construct_join_dependency_for_association_find
+ join_dependency = construct_join_dependency
relation = construct_relation_for_association_find(join_dependency)
relation = relation.except(:select, :order).select("1 AS one").limit(1)
@@ -201,23 +201,21 @@ def raise_record_not_found_exception!(ids, result_size, expected_size) #:nodoc:
protected
def find_with_associations
- join_dependency = construct_join_dependency_for_association_find
+ join_dependency = construct_join_dependency
relation = construct_relation_for_association_find(join_dependency)
rows = connection.select_all(relation, 'SQL', relation.bind_values.dup)
join_dependency.instantiate(rows)
rescue ThrowResult
[]
end
- def construct_join_dependency_for_association_find
+ def construct_join_dependency(joins = [])
including = (eager_load_values + includes_values).uniq
- ActiveRecord::Associations::JoinDependency.new(@klass, including, [])
+ ActiveRecord::Associations::JoinDependency.new(@klass, including, joins)
end
def construct_relation_for_association_calculations
- including = (eager_load_values + includes_values).uniq
- join_dependency = ActiveRecord::Associations::JoinDependency.new(@klass, including, arel.froms.first)
- apply_join_dependency(self, join_dependency)
+ apply_join_dependency(self, construct_join_dependency(arel.froms.first))
end
def construct_relation_for_association_find(join_dependency)

0 comments on commit 75fe743

Please sign in to comment.
Something went wrong with that request. Please try again.