Skip to content

Commit

Permalink
nilify blank strings if previous value was nil
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalyi committed May 26, 2014
1 parent 46c6c57 commit b431f04
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/ooor/type_casting.rb
Expand Up @@ -107,7 +107,9 @@ def sanitize_attribute(skey, value)
true
elsif type == 'boolean'&& value == 0 || value == "0"
false
elsif value == false and type != 'boolean'
elsif value == false && type != 'boolean'
nil
elsif (type == 'char' || type == 'text') && value == "" && @attributes[skey] == nil
nil
else
value
Expand All @@ -120,13 +122,13 @@ def sanitize_association(skey, value)
elsif value.is_a?(Array) && !self.class.many2one_associations.keys.index(skey)
value.reject {|i| i == ''}.map {|i| i.is_a?(String) ? i.to_i : i}
elsif value.is_a?(String)
sanitize_associatio_as_string(skey, value)
sanitize_association_as_string(skey, value)
else
value
end
end

def sanitize_associatio_as_string(skey, value)
def sanitize_association_as_string(skey, value)
if self.class.polymorphic_m2o_associations.has_key?(skey)
value
elsif self.class.many2one_associations.has_key?(skey)
Expand Down

0 comments on commit b431f04

Please sign in to comment.