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:
Kristian Dupont 2016-12-20 16:28:02 +01:00 committed by GitHub
parent 112cda2e4f
commit c1e7ddcda1
2 changed files with 10 additions and 0 deletions

View File

@ -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)) {
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);
table->move_last_over(object->row().get_index());
}

View File

@ -595,6 +595,12 @@ module.exports = {
realm.delete(threeObjects);
TestCase.assertEqual(objects.length, 4, 'wrong object count');
TestCase.assertEqual(threeObjects.length, 0, 'threeObject should have been deleted');
var o = objects[0];
realm.delete(o);
TestCase.assertThrows(function() {
realm.delete(o);
});
});
},