I try to have such code:
Query<Card> query = ofy().load().type(Card.class);
UserData creator = ofy().load().type(UserData.class).id(creatorId).now();
if (creator != null && UserType.USER.equals(creator.getUserType())) {
query.filter("creator", creator);
}
if (orderColumnName != null) {
query.order((ascending ? "" : "-") + orderColumnName);
}
query.offset(startRow).limit(limit);
return query.list();
But it doesn't filter. Also this filter:
UserData creator = ofy().load().type(UserData.class).id(creatorId).now();
Query<Card> query = ofy().load().type(Card.class).filter("creator", creator);
Any idea why?
EDITED
My class Card.java
@Entity
public class Card implements PersistableObject {
@Id
Long id;
@Index
Date createDate;
...
@Index
Ref<UserData> creator;
...
public UserData getCreator() {
if (creator != null) {
return creator.get();
}
return null;
}
public void setCreator(UserData creator) {
this.creator = Ref.create(creator);
}
}
My class UserData.java
@Entity
public class UserData implements PersistableObject {
@Id
Long id;
Ref<EaistoAccount> eaistoAccount;
UserType userType;
public EaistoAccount getEaistoAccount() {
if (eaistoAccount == null) {
return null;
}
return eaistoAccount.get();
}
public void setEaistoAccount(EaistoAccount aistoAccount) {
this.eaistoAccount = Ref.create(aistoAccount);
}
}
It doesn't work means that I expect to get filtered entities to corresponding UserData but it doesn't filter when I split query in a few parts also it filters when I use query in one line.
I have found a solution:
https://code.google.com/p/objectify-appengine/wiki/FrequentlyAskedQuestions