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

Tree structures aren't automatically persisted when using custom ids #49

Open
NickRussell95 opened this issue Feb 4, 2021 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@NickRussell95
Copy link

Describe the bug
I have a basic model hierarchy built up of ToMany & ToOne relations:

  • Favourites with ToMany<Product>
    • Product with 3 different ToOne<ProductMetaData>
      • ProductMetaData no further relations

The Favourites object uses ObjectBox auto id, but the Product and ProductMetaData come from a remote database so I am manually assigning the Id property using:

objectbox: id = { "assignable": true }

According to this documentation you don't have to manually add the child objects, the tree will automatically be put:

You can persist whole trees of object relations at once: If the customer object does not yet exist in the database, the ToOne will put() it. If it already exists, the ToOne will only create the relation (but not put() it).

This doesn't appear to be happening with my structure because I am using manually assigned Ids (is this by design?). The tree does get populated if I use the auto id, but then I quickly end up with duplicate objects in the local store each time new data is fetched from the remote database. I can put a unique constraint on the database id & use ObjectBox auto id, but then I run into this long running issue.

Basic info:

  • ObjectBox version 1.4.1
  • Reproducibility: always
  • Device: iPhone X
  • OS: iOS 14.3

To Reproduce

  1. Define an object structure similar to the one described above
  2. Create a Favourites object and assign it a list of Product (none of which has been put into the store so far)
  3. objectStore.box(for: Favourites.self).put(myFavouritesInstance)
  4. The Favourites object is stored, but none of its child relations are

Expected behavior
Based on the documentation I would expend the child tree to be auto populated.

@NickRussell95 NickRussell95 added the bug Something isn't working label Feb 4, 2021
@greenrobot
Copy link
Member

Yes, unfortunately it's not possible to have this convenience with self-assigned IDs. The workaround is to put the objects before using them in relation. The same limitation applies to Java, but we have some hint boxes in the docs there. We should do the same for Swift.

@greenrobot greenrobot removed the bug Something isn't working label Feb 25, 2021
@greenrobot-team greenrobot-team added the documentation Improvements or additions to documentation label Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants