google app engine - Objectify optionally load referenced attributes -


i have useraccount has list of followings. list of followings saved own entity. don't need following list and, thus, don't use @load. however, have situation load multiple useraccounts followings.

so, need this:

ofyservice.ofy().load().type(useraccount.class).limit(200).loadreference("followerref").list(); 

example useraccount:

@entity @cache public class useraccount {     @id private string email;     @index     private string nickname;     private ref<userfollowing> followingref; } 

i believe objectify provides way after in form of load groups. rightly pointed out using @load annotation automatically retrieve useraccounts's followingref don't want happen cases.

in order load list of useraccount followingref first have apply following simple modifications entity:

@entity public class useraccount {     public static class {}      @id long id;     @load(everything.class) ref<userfollowing> followingref; } 

you can following load single useraccount object:

// doesn't load followingref useraccount ua = ofy().load().key(useraccountkey).now();  // load followingref useraccount ua = ofy().load().group(everything.class).key(useraccountkey).now(); 

similary load list of useraccount objects followinfref:

// in case you'd list<useraccount> accounts = ofy().load()                                   .type(useraccount.class)                                   .group(everything.class)                                   .list(); 

that should solve problem. don't know if code compiles if doesn't shouldn't hard fix.

for further reading click here , scroll down load groups section


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -