diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-09-22 11:21:28 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2010-09-22 18:08:02 -0300 |
commit | ea35ccfe2014aff208601b98442ff03fa76269a9 (patch) | |
tree | de8258e0dd1a5b3c0f844c8809b1e52b65cc1c6e /activerecord/lib/active_record | |
parent | 0580f5a6ac78340ececb43981c6731817c1031aa (diff) | |
download | rails-ea35ccfe2014aff208601b98442ff03fa76269a9.tar.gz rails-ea35ccfe2014aff208601b98442ff03fa76269a9.tar.bz2 rails-ea35ccfe2014aff208601b98442ff03fa76269a9.zip |
Perf: refactor method.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index 605bc9c66f..eb65234dfb 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -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 |