Skip to content

Commit 3413b88

Browse files
committed
Replace map.flatten with flat_map in activerecord
1 parent 817fe31 commit 3413b88

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

activerecord/lib/active_record/associations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ def association_instance_set(name, association)
530530
# end
531531
#
532532
# @firm = Firm.first
533-
# @firm.clients.collect { |c| c.invoices }.flatten # select all invoices for all clients of the firm
534-
# @firm.invoices # selects all invoices by going through the Client join model
533+
# @firm.clients.flat_map { |c| c.invoices } # select all invoices for all clients of the firm
534+
# @firm.invoices # selects all invoices by going through the Client join model
535535
#
536536
# Similarly you can go through a +has_one+ association on the join model:
537537
#

activerecord/lib/active_record/associations/preloader/through_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def associated_records_by_owner(preloader)
2323

2424
reset_association owners, through_reflection.name
2525

26-
middle_records = through_records.map { |(_,rec)| rec }.flatten
26+
middle_records = through_records.flat_map { |(_,rec)| rec }
2727

2828
preloaders = preloader.preload(middle_records,
2929
source_reflection.name,

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def create_table(table_name, options = {}) #:nodoc:
459459
end
460460

461461
def bulk_change_table(table_name, operations) #:nodoc:
462-
sqls = operations.map do |command, args|
462+
sqls = operations.flat_map do |command, args|
463463
table, arguments = args.shift, args
464464
method = :"#{command}_sql"
465465

@@ -468,7 +468,7 @@ def bulk_change_table(table_name, operations) #:nodoc:
468468
else
469469
raise "Unknown method called : #{method}(#{arguments.inspect})"
470470
end
471-
end.flatten.join(", ")
471+
end.join(", ")
472472

473473
execute("ALTER TABLE #{quote_table_name(table_name)} #{sqls}")
474474
end

activerecord/test/cases/associations/callbacks_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_has_and_belongs_to_many_remove_callback_on_clear
159159
activerecord.reload
160160
assert activerecord.developers_with_callbacks.size == 2
161161
end
162-
log_array = activerecord.developers_with_callbacks.collect {|d| ["before_removing#{d.id}","after_removing#{d.id}"]}.flatten.sort
162+
log_array = activerecord.developers_with_callbacks.flat_map {|d| ["before_removing#{d.id}","after_removing#{d.id}"]}.sort
163163
assert activerecord.developers_with_callbacks.clear
164164
assert_equal log_array, activerecord.developers_log.sort
165165
end

activerecord/test/cases/autosave_association_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ def assert_no_difference_when_adding_callbacks_twice_for(model, association_name
7676
end
7777

7878
def callbacks_for_model(model)
79-
model.instance_variables.grep(/_callbacks$/).map do |ivar|
79+
model.instance_variables.grep(/_callbacks$/).flat_map do |ivar|
8080
model.instance_variable_get(ivar)
81-
end.flatten
81+
end
8282
end
8383
end
8484

0 commit comments

Comments
 (0)