aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-06-27 23:30:40 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-08-18 09:55:37 -0300
commita0f9dc7657cca1bbee4957b8cff884dcb53a3d1b (patch)
treef8e6eda7749bd2f038e898605b4bdfb3315932b7 /activerecord
parent2a700a03cee5366ad4a9af5b5f3a9c31a7e991fd (diff)
downloadrails-a0f9dc7657cca1bbee4957b8cff884dcb53a3d1b.tar.gz
rails-a0f9dc7657cca1bbee4957b8cff884dcb53a3d1b.tar.bz2
rails-a0f9dc7657cca1bbee4957b8cff884dcb53a3d1b.zip
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.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_assignment.rb11
1 files changed, 6 insertions, 5 deletions
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