0
votes

I am using Objectbox and have setup several Entities. My entities contain references to other entities. For example:

@Entity 
class EntityA {

    @Id
    var id: Long = 0
    lateinit var bEntities: ToMany<EntityB>

    fun addB(b: EntityB) {
        bEntities.add(b)
        b.entityA.target = this
    }
}


@Entity 
class EntityB {

    @Id
    var id: Long = 0
    lateinit var entityA: ToOne<EntityA>
}

I am able to create EntityA and link it to all my EntityB. Then I am able to store EntityA and recover all of it's information along with the EntityB objects linked to it.

My question is: If I want to update one of the EntityB that is linked to EntityA would I have to get a Box for EntityB and put the updated object in that box? Or should I be able to update the EntityB object by changing it's values and then updating the Box for EntityA which contains the EntityB object?

1

1 Answers

1
votes

If you update entityB then use boxB to put it.

If you add new enititB objects to entityA: just put entityA using boxA and all changes to the relationship including new entityB objects are persisted.