Skip to content

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

Open
@NickRussell95

Description

@NickRussell95

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions