简体   繁体   中英

Querying 2 Entities With Objectify

I have 2 diferent Entities:

  • USER :

     @Entity public class UserMW { @Id private Long id; private String name; private Long score; ... } 
  • USER_CHALLENGE

     @Entity public class UserChallengeMW { @Id private Long id; @Index private Ref<UserMW> user; @Index @Load private Ref<ChallengeMW> challenge; } 

I want to be able to get one ChallengeMW object and query all users which have done this ChallengeMW. So far it's pretty simple. I just need to query USER_CHALLENGE filtering by "Ref challenge". Something like this:

ofy().load().type(UserChallengeMW.class).filter("challenge", challengeRef).list();

The problem is , I want to order it according to the property " score " into USER entity. Any idea about what is the correct way to go?

Unfortunately, there are no joins in the datastore. Either denormalize the 'score' into the UserChallengeMW object or query for all the data and sort it in memory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM