Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting only unique values in objectbox entity

Tags:

objectbox

Is there something similar to this: @Insert(onConflict = OnConflictStrategy.REPLACE) as found in Room database that you can do in Objectbox. If not, how can you avoid saving duplicate entries in an objectbox entity? Thanks.

like image 682
Vishnu Sookdeo Avatar asked Nov 08 '22 07:11

Vishnu Sookdeo


1 Answers

in object box DataModel class, make the item anotation

@unique Public String userID;


private Box<User> userBox;
userBox = ObjectBox.get().boxFor(User.class);

//your inserted object 

if (!userBox.getAll().contains(insertedObject)){
                        leadBoxForLeadOpions.put(l);
                    }
like image 137
Atiar Talukdar Avatar answered Dec 07 '22 02:12

Atiar Talukdar