HaxeFoundation/haxe — pull request #2609 by jasononeil (2014-02-06 10:28:29+00:00)
Title: Fix for updating DB object property to null when cache==null

The bug:

* Create an object, where one of the "SNULL" values is set to a non-null value. Save to DB.
* Create a new object, with the same values, same ID, but set the `SNULL` value to null.
* Call `update()`. Your property will keep it's old value, it will not be set to null in the db.

The issue:

* There are circumstances where an object that already exists in the
database has no cache. eg. If you create it, but set an id, or if
you transfer it over remoting, but your serialization ignores the
cache.
* When you call update() it only includes properties in the SQL "UPDATE"
query when the new value `v` is different from the cached value `vc`.
* The cached value is retrieved with "Reflect.field", so if there is no
cache, `vc == null`.
* If your existing object had a property which previously was set to a
non-null value, but now you want to change it to null, it will not be
included in the "UPDATE" query, because `vc==null` and `v==null`, therefore
`vc==v`, we assume the value has not changed and don't include it in the query.

The resolution:

* If the cache==null, ensure all fields are set during your "UPDATE"
query, because you cannot be sure which properties have changed.