mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 06:46:03 +00:00
Throw when deleting detached object (#694)
* Throw when deleting detached object * Update error message * Add user file * Throw when deleting detached object * Update error message * Revert "Add user file" This reverts commit 2948f4cfc2dfd2d5d75594307b1e89806b817eb7.
This commit is contained in:
parent
112cda2e4f
commit
c1e7ddcda1
@ -565,6 +565,10 @@ void RealmClass<T>::delete_one(ContextType ctx, ObjectType this_object, size_t a
|
|||||||
|
|
||||||
if (Object::template is_instance<RealmObjectClass<T>>(ctx, arg)) {
|
if (Object::template is_instance<RealmObjectClass<T>>(ctx, arg)) {
|
||||||
auto object = get_internal<T, RealmObjectClass<T>>(arg);
|
auto object = get_internal<T, RealmObjectClass<T>>(arg);
|
||||||
|
if (!object->is_valid()) {
|
||||||
|
throw std::runtime_error("Object is invalid. Either it has been previously deleted or the Realm it belongs to has been closed.");
|
||||||
|
}
|
||||||
|
|
||||||
realm::TableRef table = ObjectStore::table_for_object_type(realm->read_group(), object->get_object_schema().name);
|
realm::TableRef table = ObjectStore::table_for_object_type(realm->read_group(), object->get_object_schema().name);
|
||||||
table->move_last_over(object->row().get_index());
|
table->move_last_over(object->row().get_index());
|
||||||
}
|
}
|
||||||
|
@ -595,6 +595,12 @@ module.exports = {
|
|||||||
realm.delete(threeObjects);
|
realm.delete(threeObjects);
|
||||||
TestCase.assertEqual(objects.length, 4, 'wrong object count');
|
TestCase.assertEqual(objects.length, 4, 'wrong object count');
|
||||||
TestCase.assertEqual(threeObjects.length, 0, 'threeObject should have been deleted');
|
TestCase.assertEqual(threeObjects.length, 0, 'threeObject should have been deleted');
|
||||||
|
|
||||||
|
var o = objects[0];
|
||||||
|
realm.delete(o);
|
||||||
|
TestCase.assertThrows(function() {
|
||||||
|
realm.delete(o);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user