From 101024aabcac50a2f8095b2960404bd1a93b1022 Mon Sep 17 00:00:00 2001 From: Eric Watson Date: Thu, 21 May 2009 14:37:21 -0500 Subject: [PATCH] Changed CastedModel so it does not cast nil values --- lib/couchrest/mixins/properties.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/couchrest/mixins/properties.rb b/lib/couchrest/mixins/properties.rb index 171a056..e4a94e3 100644 --- a/lib/couchrest/mixins/properties.rb +++ b/lib/couchrest/mixins/properties.rb @@ -56,12 +56,8 @@ module CouchRest else # Let people use :send as a Time parse arg klass = ::CouchRest.constantize(target) - # I'm not convince we should or should not create a new instance if we are casting a doc/extended doc without default value and nothing was passed - # unless (property.casted && - # (klass.superclass == CouchRest::ExtendedDocument || klass.superclass == CouchRest::Document) && - # (self[key].nil? || property.default.nil?)) - klass.send(property.init_method, self[key]) - #end + # Only cast this key if it has a value. Otherwise, leave nil. + self[key].nil? ? nil : klass.send(property.init_method, self[key]) end self[property.name].casted_by = self if self[property.name].respond_to?(:casted_by) end