mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
DRY-up join dependency creation by extracting construct_join_depdency
This commit is contained in:
parent
88219cc88a
commit
75fe7434a8
1 changed files with 5 additions and 7 deletions
|
@ -160,7 +160,7 @@ module ActiveRecord
|
||||||
conditions = conditions.id if Base === conditions
|
conditions = conditions.id if Base === conditions
|
||||||
return false if !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 = construct_relation_for_association_find(join_dependency)
|
||||||
relation = relation.except(:select, :order).select("1 AS one").limit(1)
|
relation = relation.except(:select, :order).select("1 AS one").limit(1)
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ module ActiveRecord
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def find_with_associations
|
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)
|
relation = construct_relation_for_association_find(join_dependency)
|
||||||
rows = connection.select_all(relation, 'SQL', relation.bind_values.dup)
|
rows = connection.select_all(relation, 'SQL', relation.bind_values.dup)
|
||||||
join_dependency.instantiate(rows)
|
join_dependency.instantiate(rows)
|
||||||
|
@ -209,15 +209,13 @@ module ActiveRecord
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
def construct_join_dependency_for_association_find
|
def construct_join_dependency(joins = [])
|
||||||
including = (eager_load_values + includes_values).uniq
|
including = (eager_load_values + includes_values).uniq
|
||||||
ActiveRecord::Associations::JoinDependency.new(@klass, including, [])
|
ActiveRecord::Associations::JoinDependency.new(@klass, including, joins)
|
||||||
end
|
end
|
||||||
|
|
||||||
def construct_relation_for_association_calculations
|
def construct_relation_for_association_calculations
|
||||||
including = (eager_load_values + includes_values).uniq
|
apply_join_dependency(self, construct_join_dependency(arel.froms.first))
|
||||||
join_dependency = ActiveRecord::Associations::JoinDependency.new(@klass, including, arel.froms.first)
|
|
||||||
apply_join_dependency(self, join_dependency)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def construct_relation_for_association_find(join_dependency)
|
def construct_relation_for_association_find(join_dependency)
|
||||||
|
|
Loading…
Reference in a new issue