提交 ea35ccfe 编写于 作者: E Emilio Tagua 提交者: Santiago Pastorino

Perf: refactor method.

Signed-off-by: NSantiago Pastorino <santiago@wyeworks.com>
上级 0580f5a6
......@@ -49,23 +49,20 @@ def insert_record(record, force = true, validate = true)
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册