Realm Java Android: Create or update object
Asked Answered
L

1

5

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.

Lentha answered 10/9, 2017 at 5:55 Comment(0)
D
8

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)

Distribution answered 10/9, 2017 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.