Damnum
Damnum

Reputation: 1859

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.

Upvotes: 5

Views: 2004

Answers (1)

EpicPandaForce
EpicPandaForce

Reputation: 81539

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)

Upvotes: 8

Related Questions