With io.realm.kotlin:library-base:0.10.0 when tryi...
# realm
j
With io.realm.kotlinlibrary base0.10.0 when trying to run
Copy code
suspend fun delete(){
    val users = realm.query<UserDao>().find()
    realm.write {
        delete(users)
    }
}
Throws: java.lang.IllegalStateException: Could not execute the write transaction: RealmCoreException([5]: Must be in a write transaction) for kotlin multiplatform 1.6.10, this happens currently on Android Am I doing something wrong?
c
The objects retrieved from the query are immutable and tied to the version of the realm when issuing the query. You need to ensure that you operate on the latest versions of the objects inside the write transaction with
findLatest
as shown in https://github.com/realm/realm-kotlin#update But in your case, where you are immediately looking up the objects, you can also just do the actual query inside the write-block as shown in https://github.com/realm/realm-kotlin#delete
j
@Claus Rørbech So totally removing the database(i.e the application) should have the same effect then? Because it is still there even with a fresh install
running
query<UserDao>()
directly in delete seems to work
111 Views