objectbox / objectbox/objectbox-java

Provide a way to force a refresh of the cached ToOne target

Open
#1,002 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
4.6k
Forks
311
PR merge metrics
No merged PRs in 30d

Description

When the target entity of a ToOne relationship is changed after it's resolved and cached, there is no way to force the target to refresh from the database.

Describe the solution you'd like
Provide a function that can be called that forces a new "get" from the box, caches the new entity, and returns it. This can be used when the app knows that the entity has been updated but wants those changes reflected in the related object.

Describe alternatives you've considered
As a workaround/alternative, the app can find the correct box, get an updated entity using the getTargetId(), then set the ToOne target entity to the updated entity. This works but requires a lot of extra code for something it feels like objectbox should be able to handle (especially since the ToOne relationship already knows the correct box for the get operation).

Additional context
Currently using this on Kotlin/Android.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the ToOne relationship API and read the existing getTargetId() and target setter behavior. Implement the requested refresh operation so it gets the related entity from its known box, updates the cache, and returns the entity; done means callers can refresh a changed target without manually finding the box.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, kotlin
Domain
databases, mobile-dev
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.