fix for partial update of string properties

This commit is contained in:
Ari Lazier 2015-09-03 14:37:22 -07:00
parent ee87cbc17a
commit cc0f821a99
3 changed files with 30 additions and 2 deletions

View File

@ -102,6 +102,12 @@ JSObjectRef RJSObjectCreate(JSContextRef ctx, Object object) {
return jsObject;
}
template<> bool RJSAccessor::dict_has_value_for_key(JSContextRef ctx, JSValueRef dict, const std::string &prop_name) {
JSObjectRef object = RJSValidatedValueToObject(ctx, dict);
JSStringRef propStr =JSStringCreateWithUTF8CString(prop_name.c_str());
return JSObjectHasProperty(ctx, object, propStr);
}
template<> JSValueRef RJSAccessor::dict_value_for_key(JSContextRef ctx, JSValueRef dict, const std::string &prop_name) {
JSObjectRef object = RJSValidatedValueToObject(ctx, dict);
JSStringRef propStr =JSStringCreateWithUTF8CString(prop_name.c_str());

View File

@ -29,6 +29,7 @@ namespace realm {
//
// Value converters - template specializations must be implemented for each platform
//
static bool dict_has_value_for_key(ContextType ctx, ValueType dict, const std::string &prop_name);
static ValueType dict_value_for_key(ContextType ctx, ValueType dict, const std::string &prop_name);
static bool to_bool(ContextType ctx, ValueType &val);
@ -183,9 +184,9 @@ namespace realm {
// populate
Object object(realm, object_schema, table->get(row_index));
for (Property &prop : object_schema.properties) {
ValueType prop_value = Accessor::dict_value_for_key(ctx, value, prop.name);
if (prop_value) {
if (Accessor::dict_has_value_for_key(ctx, value, prop.name)) {
if (created || !prop.is_primary) {
ValueType prop_value = Accessor::dict_value_for_key(ctx, value, prop.name);
object.set_property_value_impl(ctx, prop, prop_value, try_update);
}
}

View File

@ -98,6 +98,27 @@ var RealmTests = {
realm.create('IntPrimaryObject', [0, 'newVal0'], true);
TestCase.assertEqual(obj0.valueCol, 'newVal0');
TestCase.assertEqual(objects.length, 2);
realm.create('IntPrimaryObject', {primaryCol: 0}, true);
TestCase.assertEqual(obj0.valueCol, 'newVal0');
});
realm.write(function() {
var obj0 = realm.create('StringPrimaryObject', ['0', 'val0']);
TestCase.assertThrows(function() {
realm.create('StringPrimaryObject', ['0', 'val0']);
});
realm.create('StringPrimaryObject', ['1', 'val1'], true);
var objects = realm.objects('StringPrimaryObject');
TestCase.assertEqual(objects.length, 2);
realm.create('StringPrimaryObject', ['0', 'newVal0'], true);
TestCase.assertEqual(obj0.valueCol, 'newVal0');
TestCase.assertEqual(objects.length, 2);
realm.create('StringPrimaryObject', {primaryCol: '0'}, true);
TestCase.assertEqual(obj0.valueCol, 'newVal0');
});
},