Artem Artem - 14 days ago 4x
Android Question

Adding only unique values into Realm

Is there an elegant way to add a batch of new objects from JSON, taking into consideration that the new bunch might contain values that already in DB and that DB must contain only unique values?


Why not using the same id in the JSON object?, check that a unique id is being sent from the server and prepare a method that checks out for the id if it exists.

//Check if item exists already with id

public boolean checkIfExists(String id){

    RealmQuery<Data> query = realm.where(Data.class)
            .equalTo("id", id);

    return query.count() != 0;