realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Apache License 2.0
932 stars 57 forks source link

Query On Realm Object Doesn't Emit When Embedded Realm Object is updated #1821

Open Ynnck123 opened 3 weeks ago

Ynnck123 commented 3 weeks ago

My Setup

I have the structure of the following two objects:

class MyRealmObject: RealmObject {
    @PrimaryKey
    var id: String = ""
    var myEmbeddedRealmObjects: RealmList<MyEmbeddedRealmObject> = realmListOf()
}
class MyEmbeddedRealmObject: EmbeddedRealmObject {
    var exampleEmbeddedParam: String = ""
}

Additionally I have a query on my database that looks like this:

    fun observeMyRealmObject(id: String): Flow<MyRealmObject?> = realm
        .query<MyRealmObject>("id = $0", id)
        .first()
        .asFlow()
        .mapLatest { myRealmObject: MyRealmObject -> myRealmObject.obj }

The problem

When I now update the exampleEmbeddedParam parameter of any of the MyEmbeddedRealmObject's, no new state update for my Flow gets emitted.

I learned that there is a default limitation of a nested hierarchy of 4 for the .asFlow() function, which I can overcome using the keyPaths parameter for the .asFlow() function.

However, from my perspective, the myEmbeddedRealmObjects is on a hierarchy of 2, so I the query should get notified when any of the MyEmbeddedRealmObject's exampleEmbeddedParam gets updated.

This is however not the case and only if I add an explicit keyPaths parameter like .asFlow(listOf("myEmbeddedRealmObjects.*") my query emits an update.

Question

Is it by default, that realmList parameters or any other second level EmbeddedRealmObject changes are ignored unless I explicitly use the keyPaths parameters of the .asFlow() function? And how can I overcome this problem besides using explicit keyPaths parameters for all queries that needs to get updates from embedded realm object parameters?

Any help is appreciated! Thank you in advance

sync-by-unito[bot] commented 3 weeks ago

➤ PM Bot commented:

Jira ticket: RKOTLIN-1120