martyn mlostekk martyn mlostekk - 24 days ago 7
Android Question

RealList in RealmObject not automatically loaded

i am having the following issue:

This is the class for

ProjectInfo


public class ProjectInfo extends RealmObject
{
@Getter @Setter @PrimaryKey private long projectId;
@Getter @Setter RealmList<Submission> submissions;
}


And this is the class for
Submission


public class Submission extends RealmObject
{
@Getter @Setter @PrimaryKey long id;
@Getter @Setter Date creationDate;

public Submission() {}

}


When i create the objects and save to the realm database, the reference from ProjectInfo to Submission is shown like this in the column

class_Submission{0,1,2,3}


This looks right.

But now when i load the projectInfo object with

ProjectInfo projectInfo = realm.where(ProjectInfo.class).equalTo("projectId", projectId).findFirst();


The projectInfo.submissions == null;

Do i have to do something special to automatically load references from other tables?

I am using realm version

classpath 'io.realm:realm-gradle-plugin:2.1.1'


The @Getter and @Setter are from projectLombok.

UPDATE1



While debugging i see a member called
sumbissionsRealmList
in the
ProjectInfoRealmProxy
class which has the correct values. But they are not written into the
submissions
member. What is the reason?

Answer

Of course not. All fields inside a RealmProxy are lazy-loaded. You obtain the list via getSubmissions(), which will return the list that contains the proxies of the elements. The fields themselves are just to provide the underlying Realm schema (and to load them with data for unmanaged objects, which Realm uses to populate the underlying Realm when you call insertOrUpdate or copyToRealmOrUpdate)

But this is all mentioned in the documentation:

https://realm.io/docs/java/latest/#android-studio-debugging