From a0613ad8a9773c76a9b0a256f7099fde35823674 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 5 Oct 2012 12:07:16 -0300 Subject: Revert "Use flat_map { } instead of map {}.flatten" This reverts commit abf8de85519141496a6773310964ec03f6106f3f. We should take a deeper look to those cases flat_map doesn't do deep flattening. irb(main):002:0> [[[1,3], [1,2]]].map{|i| i}.flatten => [1, 3, 1, 2] irb(main):003:0> [[[1,3], [1,2]]].flat_map{|i| i} => [[1, 3], [1, 2]] --- activerecord/lib/active_record/associations/join_dependency.rb | 4 ++-- activerecord/lib/active_record/associations/preloader.rb | 2 +- activerecord/lib/active_record/associations/preloader/association.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 16491cbee7..cd366ac8b7 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -35,12 +35,12 @@ module ActiveRecord end def columns - join_parts.flat_map { |join_part| + join_parts.collect { |join_part| table = join_part.aliased_table join_part.column_names_with_alias.collect{ |column_name, aliased_name| table[column_name].as Arel.sql(aliased_name) } - } + }.flatten end def instantiate(rows) diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index 9cbc117945..ce5bf15f10 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -106,7 +106,7 @@ module ActiveRecord def preload_hash(association) association.each do |parent, child| Preloader.new(records, parent, preload_scope).run - Preloader.new(records.flat_map { |record| record.send(parent) }, child).run + Preloader.new(records.map { |record| record.send(parent) }.flatten, child).run end end diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index 358d84513c..cbf5e734ea 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -77,7 +77,7 @@ module ActiveRecord # Some databases impose a limit on the number of ids in a list (in Oracle it's 1000) # Make several smaller queries if necessary or make one query if the adapter supports it sliced = owner_keys.each_slice(model.connection.in_clause_length || owner_keys.size) - records = sliced.flat_map { |slice| records_for(slice).to_a } + records = sliced.map { |slice| records_for(slice).to_a }.flatten end # Each record may have multiple owners, and vice-versa -- cgit v1.2.3