diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-16 13:41:24 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-16 13:41:24 -0700 |
commit | 85fe5edcec77f96923ed4f4e8b63a247ebe6b055 (patch) | |
tree | e9d69ae080f5d911c8d5729fa2dac5bd09b986cb | |
parent | 743b67508e2027e1d086142ccbec47a19fc943f6 (diff) | |
download | rails-85fe5edcec77f96923ed4f4e8b63a247ebe6b055.tar.gz rails-85fe5edcec77f96923ed4f4e8b63a247ebe6b055.tar.bz2 rails-85fe5edcec77f96923ed4f4e8b63a247ebe6b055.zip |
decouple the manager class from building join constraints
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_association.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 9 |
2 files changed, 11 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index ee1fcc17d8..3205cd41a2 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -64,7 +64,8 @@ module ActiveRecord end end - def join_to(manager) + def join_constraints + joins = [] tables = @tables.dup foreign_table = parent_table @@ -84,11 +85,10 @@ module ActiveRecord foreign_key = reflection.foreign_key when :has_and_belongs_to_many # Join the join table first... - manager.from(join( + joins << join( table, table[reflection.foreign_key]. - eq(foreign_table[reflection.active_record_primary_key]) - )) + eq(foreign_table[reflection.active_record_primary_key])) foreign_table, table = table, tables.shift @@ -125,13 +125,13 @@ module ActiveRecord constraint = constraint.and rel.arel.constraints end - manager.from(join(table, constraint)) + joins << join(table, constraint) # The current table in this iteration becomes the foreign table in the next foreign_table, foreign_klass = table, klass end - manager + joins end # Builds equality condition. diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 612c7d17a3..fb585ab8ab 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -948,10 +948,11 @@ module ActiveRecord join_dependency.graft(*stashed_association_joins) - # FIXME: refactor this to build an AST - join_dependency.join_associations.each do |association| - association.join_to(manager) - end + joins = join_dependency.join_associations.map { |association| + association.join_constraints + }.flatten + + joins.each { |join| manager.from join } manager.join_sources.concat join_list |