From a0f9dc7657cca1bbee4957b8cff884dcb53a3d1b Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 27 Jun 2012 23:30:40 -0300 Subject: Reuse already fetched column to check for :time Avoid doing a new column lookup for the attribute, since we already have the column to check for the klass. --- activerecord/lib/active_record/attribute_assignment.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/attribute_assignment.rb b/activerecord/lib/active_record/attribute_assignment.rb index 610411c0f0..e174758fd9 100644 --- a/activerecord/lib/active_record/attribute_assignment.rb +++ b/activerecord/lib/active_record/attribute_assignment.rb @@ -190,9 +190,10 @@ module ActiveRecord def read_value_from_parameter(name, values_hash_from_param) return if values_hash_from_param.values.compact.empty? - klass = (self.class.reflect_on_aggregation(name.to_sym) || column_for_attribute(name)).klass + column = self.class.reflect_on_aggregation(name.to_sym) || column_for_attribute(name) + klass = column.klass if klass == Time - read_time_parameter_value(name, values_hash_from_param) + read_time_parameter_value(column, name, values_hash_from_param) elsif klass == Date read_date_parameter_value(name, values_hash_from_param) else @@ -200,12 +201,12 @@ module ActiveRecord end end - def read_time_parameter_value(name, values_hash_from_param) + def read_time_parameter_value(column, name, values_hash_from_param) # If column is a :time (and not :date or :timestamp) there is no need to validate if # there are year/month/day fields - if column_for_attribute(name).type == :time + if column.type == :time # if the column is a time set the values to their defaults as January 1, 1970, but only if they're nil - {1 => 1970, 2 => 1, 3 => 1}.each do |key,value| + { 1 => 1970, 2 => 1, 3 => 1 }.each do |key,value| values_hash_from_param[key] ||= value end else -- cgit v1.2.3