Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Realm copyToRealmOrUpdate updates existing fields

Tags:

android

realm

When using copyToRealmOrUpdate it also overrides fields with existing values. I would expect it would only update the fields I gave and use the existing values for the other fields.

I saw this issue for createOrUpdateFromJson: https://github.com/realm/realm-java/issues/933 cmelchior says this:

It is impossible to tell the difference between an value not set and it's default value, so there it should override all properties.

I wanted to create an issue with label enhancement for realm, but instead I ask it here first. Is it really impossible? Because it would be a great improvement to me.

Thanks!

like image 937
Kevin van Mierlo Avatar asked Oct 20 '22 14:10

Kevin van Mierlo


1 Answers

Note there is difference between using Realm.copyToRealmOrupdate(RealmObject) and Realm.createOrUpdateFromJson(Json)

The answer I gave is true for copyToRealmOrUpdate() eg. you cannot tell the difference between the following in Java:

boolean bool1;
boolean bool2 = false;

It is different for JSON where you can tell if a property is missing altogether. However the current implementation doesn't work that way. We are currently in process of merging a Pull Request that actually has the behaviour you are looking for. You can follow the progress here: https://github.com/realm/realm-java/pull/1022

like image 102
Christian Melchior Avatar answered Nov 15 '22 06:11

Christian Melchior