diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-02-02 14:40:58 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-02-07 14:13:46 -0800 |
commit | 20440fd8700e1eb9725ffa0e85d458a81b519dd2 (patch) | |
tree | f53981c841e73810a9bb71d5afe44ac3cc3179de | |
parent | 94540763141a3574b9c2a96abfdcb3be601424a5 (diff) | |
download | rails-20440fd8700e1eb9725ffa0e85d458a81b519dd2.tar.gz rails-20440fd8700e1eb9725ffa0e85d458a81b519dd2.tar.bz2 rails-20440fd8700e1eb9725ffa0e85d458a81b519dd2.zip |
return early from typecasting if the value is nil
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb index 08cfa8dd69..bb2a5c0122 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb @@ -25,6 +25,8 @@ module ActiveRecord class Money def type_cast(value) + return if value.nil? + # Because money output is formatted according to the locale, there are two # cases to consider (note the decimal separators): # (1) $12,345,678.12 @@ -62,18 +64,24 @@ module ActiveRecord class Integer def type_cast(value) - value.to_i + return if value.nil? + + value.to_i rescue value ? 1 : 0 end end class Boolean def type_cast(value) + return if value.nil? + ConnectionAdapters::Column.value_to_boolean value end end class Timestamp def type_cast(value) + return if value.nil? + # FIXME: probably we can improve this since we know it is PG # specific ConnectionAdapters::Column.string_to_time value @@ -82,6 +90,8 @@ module ActiveRecord class Date def type_cast(value) + return if value.nil? + # FIXME: probably we can improve this since we know it is PG # specific ConnectionAdapters::Column.value_to_date value @@ -90,6 +100,8 @@ module ActiveRecord class Time def type_cast(value) + return if value.nil? + # FIXME: probably we can improve this since we know it is PG # specific ConnectionAdapters::Column.string_to_dummy_time value @@ -98,6 +110,8 @@ module ActiveRecord class Float def type_cast(value) + return if value.nil? + value.to_f end end |