Android realm. Passing RealmObject as parameter to constructor. Null values fields -


it seems ralmobject sets fields default values when passes constructor of other realmobject (look @ comments in code below). simple workaround don't pass object constructor , assign fields after object created. don't understand how's possible. question is: can explain what's going on, please? , in situations else should aware of behavior while working realm?

that's simple example of code reproduces issue:

 realm = realm.getdefaultinstance();  realm.executetransaction(new realm.transaction() {       @override       public void execute(realm realm) {             stock stock1 = new stock();             stock1.id = "stock1";             managedstock = realm.copytorealm(stock1);       } }); //output here: managedstock.id = stock1 log.d("mylogs", "managedstock.id = " + managedstock.id); goods goods = new goods(managedstock); 

and in constructor of goods object passed managedstock has id == null, how's possible?

public class goods extends realmobject {     @primarykey     public string id;     public stock stock;      public goods() {}      public goods(stock s) {         //output here: s.id == null         log.d("mylogs", "s.id == " + s.id);     } } 

and stock object, in case

public class stock extends realmobject {     @primarykey     public string id;     public string name; } 

some additional info: realm 1.2.0 , android 5.0, device samsung galaxy s4

thanks in advance!

this sounds realm transformer issue, made issue on realm-java github issues.

in meantime, recommend using getters/setters instead of direct field access.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -