question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update query when related entities change

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
amgadserrycommented, Mar 19, 2019

@greenrobot-team here is the final solution i went with

    fun getPopulatedAccounts(): Observable<List<AccountEntity>> {
        val zipper: BiFunction<
                Any,
                Any,
                List<AccountEntity>> = BiFunction { _, _ -> 
                    accountsDoa.findAll {
                        eager(Account_.requests)
                    }.find()
                }

        val accountsObservable = RxBoxStore.observable<Account>(accountsDoa.store)

        val requestsObservable = RxBoxStore.observable<RequestEntity>(requestDao.store)

        return Observable.combineLatest(accountsObservable, requestsObservable, zipper)
    }

let me know if there are a better workaround for rxjava. Thanks

0reactions
greenrobot-teamcommented, Sep 8, 2020

Duplicate of #268

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modifying data via the DbContext - Learn Entity Framework Core
Since the ChangeTracker tracks which properties have been modified, the context will issue a SQL statement that updates only those properties that were...
Read more >
How to update related entities in Entity Framework
I solved it by changing ClassA with a foreign key to ClassB , and setting the value of BId : public class ClassA...
Read more >
Change Tracking - EF Core - Microsoft Learn
EF Core change tracking works best when the same DbContext instance is used to both query for entities and update them by calling...
Read more >
Update Record in Entity Framework - TekTutorialsHub
We can update records either in connected or disconnected scenarios. In the connected Scenario, we open the context, query for the entity, edit...
Read more >
Modifying Data with Entity Famework Core - Code Maze
There are two ways to update rows in the database. With Connected Update and with Disconnected Update. The difference is that with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found