I'm having trouble understanding some realm behavi...
# realm
c
I'm having trouble understanding some realm behaviour. • I query for a count of records where an index value equals some value • I write another record with that same index value • I query again, but the count is unchanged. • I restart the app, and the count is now updated correctly
Copy code
// count
realm.query<RealmReport>("userId == $0", userId).count()

// write
realm.write { this.copyToRealm(newReport, updatePolicy = UpdatePolicy.ALL) }
I'm guessing there is some non-intuitive state issues going on?
c
How do you run the second query for the count?
Realm should be correctly updated, but if you are saving a “old” query, it isn’t automatically updated as it is locked to the version of the data it was created on. I.e. this would report 0 in both cases:
Copy code
val query = realm.query<RealmReport>("userId == $0", userId)
println(query.count()) // 0
realm.write { copyToRealm(Report()) } 
println(query.count()) // 0