diff options
author | Ben Woosley <ben.woosley@gmail.com> | 2013-05-10 11:53:23 +0200 |
---|---|---|
committer | Ben Woosley <ben.woosley@gmail.com> | 2013-05-10 17:46:04 +0200 |
commit | 75fe7434a81d0aaef8ec2ada8f88b5b20721c25a (patch) | |
tree | ca8c4b01a22ef1eb1f04724c502fe1ecb423355c /activerecord/lib/active_record/relation | |
parent | 88219cc88aadf75fe57a1ecacbe92a7acef64145 (diff) | |
download | rails-75fe7434a81d0aaef8ec2ada8f88b5b20721c25a.tar.gz rails-75fe7434a81d0aaef8ec2ada8f88b5b20721c25a.tar.bz2 rails-75fe7434a81d0aaef8ec2ada8f88b5b20721c25a.zip |
DRY-up join dependency creation by extracting construct_join_depdency
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index ed5fe2c683..d2cc2c7d88 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -160,7 +160,7 @@ module ActiveRecord 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 @@ module ActiveRecord 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 @@ module ActiveRecord [] 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) |