Uploaded image for project: 'Realm Kotlin'
  1. Realm Kotlin
  2. RKOTLIN-1017

Backlinks relationship is not triggering flow update

      How frequently does the bug occur?

      Always

      Description

      Flows do not get re-emitted with the latest DB state when backlinked objects are added/removed.

      Example:

      I have a City Model:

      class City : RealmObject {
          var name: String? = null
          var state: State? = null // by backlinks(State::towns)
      }
      

      And a State Model:

      class State : RealmObject {
          @PrimaryKey
          var id: String = RealmUUID.random().toString()
          var name: String? = null
          val cities: RealmResults<City> by backlinks(City::state)
      }
      

      I have a query to get all the states in a flow, very simple:

      private val states = realm.query<State>()
              .asFlow()
              .map { it.list }
      

      The idea is that whenever a new city is added/removed/changed, the flow should get the latest values from the DB, with the updated state (since it's list of cities changed, it should trigger a re-emission).

      The problem is that this is not happening! Adding or removing a city does not trigger the states query flow to update.
      The objects are being added/deleted successfully, because running the query again manually returns the most up to date version of the DB, it's just that the flow itself is not representing the latest state of the DB.

      I have managed to get it working by manually adding a keyPath to the flow builder, but that shouldn't be necessary since, according to the documentation, "If no keypaths are provided, changes to all top-level properties and nested properties 4 levels down will trigger a change."

      private val states = realm.query<State>()
              .asFlow(keyPath = listOf("cities"))
              .map { it.list }
      

      Stacktrace & log output

      No response

      Can you reproduce the bug?

      Always

      Reproduction Steps

      No response

      Version

      1.13.0

      What Atlas App Services are you using?

      Local Database only

      Are you using encryption?

      No

      Platform OS and version(s)

      Android

      Build environment

      No response

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: