2016-07-25 3 views
0

다음 목록이있는 UserAccount가 있습니다. 이 다음 목록은 자체 엔티티로 저장됩니다. 나는 보통 다음 목록을 필요로하지 않으므로 @Load를 사용하지 않습니다. 그러나, 나는 다음과 함께 여러 UserAccounts를로드하려는 상황이 있습니다. UserAccount에 대한Objectify 옵션으로로드 된 참조 속성

OfyService.ofy().load().type(UserAccount.class).limit(200).loadReference("followerRef").list(); 

예 :

그래서,이 같은 뭔가가 필요

@Entity 
@Cache 
public class UserAccount { 
    @Id private String email; 
    @Index 
    private String nickname; 
    private Ref<UserFollowing> followingRef; 
} 

답변

2

내가 Objectify가 이미 Load Groups의 형태 후에 무엇인지 할 수있는 방법을 제공합니다 생각합니다. @Load 주석을 사용하여 올바르게 지적한대로 UserAccountsfollowingRef을 자동으로 검색하므로 대부분의 경우 이러한 상황이 발생하지 않습니다.

@Entity 
public class UserAccount { 
    public static class Everything {} 

    @Id Long id; 
    @Load(Everything.class) Ref<UserFollowing> followingRef; 
} 

당신은 다음 하나의 UserAccount 객체를로드하기 위해 다음을 수행 할 수 있습니다 :

당신이 먼저 법인에 다음의 간단한 수정을 적용해야 자신의 followingRefUserAccount의 목록을로드하기 위해

// Doesn't load followingRef 
UserAccount ua = ofy().load().key(userAccountKey).now(); 

// Does load followingRef 
UserAccount ua = ofy().load().group(Everything.class).key(userAccountKey).now(); 

Similary 당신은 자신의 followinfRefUserAccount 개체의 목록을로드하기 위해이 작업을 수행 :

// In your case you'd do something like 
List<UserAccount> accounts = ofy().load() 
            .type(UserAccount.class) 
            .group(Everything.class) 
            .list(); 

그러면 문제가 해결 될 것입니다. 코드가 컴파일되는지는 모르겠지만 수정하기가 어렵지는 않습니다.

For further reading click here and scroll down to Load Groups section

+0

니스, 감사합니다. 나는 쉬운 해결책을 원했다. – OliverDeveloper