mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Perf: refactor method.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
committed by
Santiago Pastorino
parent
0580f5a6ac
commit
ea35ccfe20
@@ -49,23 +49,20 @@ module ActiveRecord
|
||||
timestamps = record_timestamp_columns(record)
|
||||
timezone = record.send(:current_time_from_proper_timezone) if timestamps.any?
|
||||
|
||||
attributes = columns.inject({}) do |attrs, column|
|
||||
attributes = Hash[columns.map do |column|
|
||||
name = column.name
|
||||
case name.to_s
|
||||
value = case name.to_s
|
||||
when @reflection.primary_key_name.to_s
|
||||
attrs[relation[name]] = @owner.id
|
||||
@owner.id
|
||||
when @reflection.association_foreign_key.to_s
|
||||
attrs[relation[name]] = record.id
|
||||
record.id
|
||||
when *timestamps
|
||||
attrs[relation[name]] = timezone
|
||||
timezone
|
||||
else
|
||||
if record.has_attribute?(name)
|
||||
value = @owner.send(:quote_value, record[name], column)
|
||||
attrs[relation[name]] = value unless value.nil?
|
||||
end
|
||||
@owner.send(:quote_value, record[name], column) if record.has_attribute?(name)
|
||||
end
|
||||
attrs
|
||||
end
|
||||
[relation[name], value] unless value.nil?
|
||||
end]
|
||||
|
||||
relation.insert(attributes)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user