javaandroidrealmrealm-java

Realm Java Android: Create or update object


In Realm Javascript, it's possible to create an object by primary key and, if it already exists, update the existing object: https://realm.io/docs/javascript/latest/#creating-and-updating-objects-with-primary-keys

How can I achieve the same in Realm Java? Didn't find this function in the docs.


Solution

  • How can I achieve the same in Realm Java? Didn't find this function in the docs.

    There are two methods for this,

    1.) copyToRealmOrUpdate() which returns the managed proxy

    2.) insertOrUpdate() which does not return the managed proxy (so it's faster when you insert many items)