Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Ynnck123 opened this issue Aug 16, 2024 Discussed in #1820 · 1 comment
Open

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

Ynnck123 opened this issue Aug 16, 2024 Discussed in #1820 · 1 comment

Comments

@Ynnck123
Copy link

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

Copy link

sync-by-unito bot commented Aug 16, 2024

➤ PM Bot commented:

Jira ticket: RKOTLIN-1120

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant