androidrealmrealm-listrealm-java

RealmList addAll duplicating object with same primary key


I have a problem in inserting objects inside a realmlist. It is duplicating my objects inside Realm, and they have the very same primary key.

class ParentObj extends RealmObject {
   RealmList<SomeObject> objects;
}

class SomeObject extends RealmObject {
   @PrimaryKey
   @Required
   String id;
   ...
}

when I get a list of SomeObject like:

List<SomeObject> objs = ...;
User.getObjects().addAll(objs);

my RealmList (objects) gets duplicated. I've made sure it is the same primary key. Anyone has any idea of what is happenning?
Thank you!


Solution

  • A RealmList works just like an ArrayList, so the same item can be there multiple times. If you want to update SomeObject you should just do that directly. The objects RealmList will reflect those changes.

    It isn't clear exactly what you are trying to do, so from the given information it is hard to give more advice.