2 Replies Latest reply on Feb 12, 2013 6:07 AM by Gerbrand Stap

    Can't reset Rhom field to nil

    Gerbrand Stap

      When a field of a Rhom object has a value in the database, it is not possible to set this field to a nil value.

       

      Given that 'Setting' is a Rhom model, the following code:

      Setting.create( 'id' => 12345 )
      s = Setting.find( :first, :conditions => { 'id' => 12345 } )
      RhoLog.info( 'Test', s.inspect )
      
      s.something = 'else'
      s.save
      s = Setting.find( :first, :conditions => { 'id' => 12345 } )
      RhoLog.info( 'Test', s.inspect )
      
      s.something = nil
      s.save
      RhoLog.info( 'Test', s.inspect )
      s = Setting.find( :first, :conditions => { 'id' => 12345 } )
      RhoLog.info( 'Test', s.inspect )
      

       

      Will result in the following logging:

        Test| {:source_id=>40040, :object=>"129212230485073.84", :id=>"12345"}

        Test| {:source_id=>40040, :object=>"129212230485073.84", :id=>"12345", :something=>"else"}

        Test| {:source_id=>40040, :object=>"129212230485073.84", :id=>"12345", :something=>nil}

        Test| {:source_id=>40040, :object=>"129212230485073.84", :id=>"12345", :something=>""}

       

      The problem is that the value in the database is set to an empty string instead of a nil value. I've tested this for both a PropertyBag and a FixedSchema and have seen the same behavior in both cases.

      The annoying side effect is that 's.something' will return nil when it has never been set, but it returns an empty string when it was saved with some value at some point in time. That's why I assume this is a bug.