1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Replace map.flatten with flat_map in activerecord

This commit is contained in:
Erik Michaels-Ober 2014-03-03 19:23:22 -08:00
parent 817fe31196
commit 3413b88a3d
5 changed files with 8 additions and 8 deletions

View file

@ -530,8 +530,8 @@ module ActiveRecord
# end
#
# @firm = Firm.first
# @firm.clients.collect { |c| c.invoices }.flatten # select all invoices for all clients of the firm
# @firm.invoices # selects all invoices by going through the Client join model
# @firm.clients.flat_map { |c| c.invoices } # select all invoices for all clients of the firm
# @firm.invoices # selects all invoices by going through the Client join model
#
# Similarly you can go through a +has_one+ association on the join model:
#

View file

@ -23,7 +23,7 @@ module ActiveRecord
reset_association owners, through_reflection.name
middle_records = through_records.map { |(_,rec)| rec }.flatten
middle_records = through_records.flat_map { |(_,rec)| rec }
preloaders = preloader.preload(middle_records,
source_reflection.name,

View file

@ -459,7 +459,7 @@ module ActiveRecord
end
def bulk_change_table(table_name, operations) #:nodoc:
sqls = operations.map do |command, args|
sqls = operations.flat_map do |command, args|
table, arguments = args.shift, args
method = :"#{command}_sql"
@ -468,7 +468,7 @@ module ActiveRecord
else
raise "Unknown method called : #{method}(#{arguments.inspect})"
end
end.flatten.join(", ")
end.join(", ")
execute("ALTER TABLE #{quote_table_name(table_name)} #{sqls}")
end

View file

@ -159,7 +159,7 @@ class AssociationCallbacksTest < ActiveRecord::TestCase
activerecord.reload
assert activerecord.developers_with_callbacks.size == 2
end
log_array = activerecord.developers_with_callbacks.collect {|d| ["before_removing#{d.id}","after_removing#{d.id}"]}.flatten.sort
log_array = activerecord.developers_with_callbacks.flat_map {|d| ["before_removing#{d.id}","after_removing#{d.id}"]}.sort
assert activerecord.developers_with_callbacks.clear
assert_equal log_array, activerecord.developers_log.sort
end

View file

@ -76,9 +76,9 @@ class TestAutosaveAssociationsInGeneral < ActiveRecord::TestCase
end
def callbacks_for_model(model)
model.instance_variables.grep(/_callbacks$/).map do |ivar|
model.instance_variables.grep(/_callbacks$/).flat_map do |ivar|
model.instance_variable_get(ivar)
end.flatten
end
end
end