Skip to content

Update query when related entities change #387

@alekop

Description

@alekop

Is there a way for an observable query to detect when a related entity changes, and notify its subscribers? The following uses a one-to-one relationship between a person and an address. I would like the person query to be notified when a person's address changes.

@Entity
data class Person(@Id val id: Long = 0) {
    lateinit var homeAddress: ToOne<Address>
}

@Entity
data class Address(@Id var id: Long = 0,
    val street: String
)

// Build a query for the parent
val query = boxStore.boxFor<Person>().query().build()
query.find()

// I want to be notified when the address changes
query.subscribe(...)

// Update the relationship
person.homeAddress.target = Address(street= "...")
boxStore.boxFor<Address>.put(newAddress) // persists, but the person query does not get notified

This updates the address box as expected, but the person query is not notified. Any way to accomplish that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions