diff options
author | Guillermo Álvarez <guillermo@cientifico.net> | 2011-02-03 00:26:39 +0100 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-03 09:08:45 -0800 |
commit | 351331fb343cdf17baa078943898ded6caff9d65 (patch) | |
tree | 8b57684788395cbe899a27c24f51a990eb416584 /activerecord/lib/active_record/coders | |
parent | 080345baca1076a9788dff4803153600aec31f86 (diff) | |
download | rails-351331fb343cdf17baa078943898ded6caff9d65.tar.gz rails-351331fb343cdf17baa078943898ded6caff9d65.tar.bz2 rails-351331fb343cdf17baa078943898ded6caff9d65.zip |
Make serialized columns with explicit object_type return a new instance of the object instead of nil
Diffstat (limited to 'activerecord/lib/active_record/coders')
-rw-r--r-- | activerecord/lib/active_record/coders/yaml_column.rb | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/coders/yaml_column.rb b/activerecord/lib/active_record/coders/yaml_column.rb index fcecc11aba..fb59d9fb07 100644 --- a/activerecord/lib/active_record/coders/yaml_column.rb +++ b/activerecord/lib/active_record/coders/yaml_column.rb @@ -19,6 +19,7 @@ module ActiveRecord end def load(yaml) + return object_class.new if object_class != Object && yaml.nil? return yaml unless yaml.is_a?(String) && yaml =~ /^---/ begin obj = YAML.load(yaml) @@ -27,6 +28,7 @@ module ActiveRecord raise SerializationTypeMismatch, "Attribute was supposed to be a #{object_class}, but was a #{obj.class}" end + obj ||= object_class.new if object_class != Object obj rescue *RESCUE_ERRORS |