Skip to content

Commit

Permalink
Replace map.flatten with flat_map in activerecord
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Mar 4, 2014
1 parent 817fe31 commit 3413b88
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ def association_instance_set(name, association)
# 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:
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def associated_records_by_owner(preloader)

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def create_table(table_name, options = {}) #:nodoc:
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"

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

execute("ALTER TABLE #{quote_table_name(table_name)} #{sqls}")
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/associations/callbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_has_and_belongs_to_many_remove_callback_on_clear
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
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/autosave_association_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def assert_no_difference_when_adding_callbacks_twice_for(model, association_name
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

Expand Down

0 comments on commit 3413b88

Please sign in to comment.