For tests, we need to clear/truncate all the tables.
What's the best what to do that?
I'm currently iterating through each and realm.objects(name).delete(results);
Is there one method to start over the whole db?
In the objc binding we have a function deleteAllObjects. We can add this to the js binding.
Another way to go about this is to simply delete the realm files between tests. The path of the default realm can be accessed without opening the realm by accessing the property Realm.defaultPath
Thanks.
I was doing the deleting before, but it won't work. I used to delete everything in the document directory and hot-reload to flush the memory.
It doesn't work because I don't relaunch the whole app, it's just that reload. As I noted in some other issue, the code now only seems to generate/migrate on real app launch and not these "command+R" reloads.
No now, I'm skipping the realm files in the delete from the document directory and will be calling deleteAllObjects when that becomes available.
This has been added in the form of:
realm.deleteAll();
works! :+1:
Hello, did not work for me :/
try {
realm.write(() => {
realm.deleteAll()
})
} catch (err) {
if (err) Promise.reject(new Error(Error. Log: ${err}))
}
I received this message:
Acecessing object of type Message which has been invalidated or deleted.
Obs; 'Message' is my schema.
I'm @brunovalenga. I'm trying to fix this for me as well.
You most likely have some realm object references in your store (or something similar) that are still being called after you nuked realm.
Best thing to do would refresh your state to the initial state so that all references are collected by the garbage collector.
Most helpful comment
This has been added in the form of: