I use Objectify in AppEngine with JAva. I would like to model a many-many relationship in which the resolution entity has additional fields, as below
@Entity
public class Account {
public @Id Long id;
public String name;
}
@Entity
public class Baby {
@Id public Long id;
public String name;
}
@Entity
public class AccountBaby {
public @Id Long id;
@Index
@ApiResourceProperty(ignored = AnnotationBoolean.TRUE)
public Ref<Account> account;
@Index
@ApiResourceProperty(ignored = AnnotationBoolean.TRUE)
public Ref<Baby> baby;
public int permission;
}
If I follow this model, I can not query list of account for given baby's id (or list of baby for given account's id) as the query below
List<AccountBaby> babies = OfyService.ofy().load().type(AccountBaby.class).filter("account=",
Key.create(Account.class, accountId)).list();
Is they any other way to query or model this relationship?
答案 0 :(得分:3)
“account =”中需要一个空格。或者你可以放弃隐含的“=”。
您实际搜索的是一个名为“account =”的属性(可以使用低级别api保存在数据存储区中)。这在filter()
方法的javadoc中提到。