Nil return value on belongs_to association should be handled gracefully

There was an issue in `SObject.write_value` where a nil value for a belongs to association would cause an error: undefined method 'id' for Array. This change set fixes that bug and cleans up the case statement in `write_value`