Permalink
Browse files

Perf: refactor method.

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
miloops authored and spastorino committed Sep 22, 2010
1 parent 093a30a commit 27cfb3e7bbf9be45f233c3e556016e5abea2dec5
Showing with 8 additions and 11 deletions.
  1. +8 −11 activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -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

0 comments on commit 27cfb3e

Please sign in to comment.