Realm Java Android: Create or update object

1.9k views Asked by At

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.

1

There are 1 answers

0
EpicPandaForce On BEST ANSWER

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)