提交 75fe7434 编写于 作者: B Ben Woosley

DRY-up join dependency creation by extracting construct_join_depdency

上级 88219cc8
......@@ -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,7 +201,7 @@ 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)
......@@ -209,15 +209,13 @@ def find_with_associations
[]
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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册