在嵌入式参考列表中对象化查询
Objectify query amongst embedded Ref list
在我的数据存储中,我有一个 post 实体,它有一个发件人,这个发件人有一个位置列表。基本上,这看起来像这样:
@Entity
@Cache
@Unindex
@Searchable
public class Post {
@Index
@Load(WithSender.class)
@NonNull @Getter @Setter
protected Ref<User> sender;
@Index
@Getter
protected long creation;
}
@Entity
@Cache
@Unindex
public class User {
@Index
@NotNull
@Email
@NonNull
@Getter
@Setter
private String email;
@Size(max = 50)
@Getter
@Setter
private String firstName;
@Size(max = 50)
@Getter
@Setter
private String lastName;
@Index
@Setter
@Getter
protected List<Key<Region>> regions;
}
我想做的是能够查询属于该用户区域列表中的区域的用户发送的所有 posts,并按顺序查询创作。
基本上,我试过这样做:
query = query.filter("sender.regions", "key").order("-creation");
当我第一次执行查询时,AppEngine 要求我创建这个索引:
<datastore-index kind="Post" ancestor="false" source="manual">
<property name="sender.regions" direction="asc"/>
<property name="creation" direction="desc"/>
</datastore-index>
但结果仍然毫无希望...如果有人有建议,我会很高兴。谢谢!
为了通过 "sender.regions" 查询 Post,应该嵌入发件人实体。
数据存储中没有 SQL 和 "join" 一样。您可以将发件人嵌入 post 或首先按区域查询发件人密钥,然后使用这些发件人密钥查询 Posts。
希望对您有所帮助。
在我的数据存储中,我有一个 post 实体,它有一个发件人,这个发件人有一个位置列表。基本上,这看起来像这样:
@Entity
@Cache
@Unindex
@Searchable
public class Post {
@Index
@Load(WithSender.class)
@NonNull @Getter @Setter
protected Ref<User> sender;
@Index
@Getter
protected long creation;
}
@Entity
@Cache
@Unindex
public class User {
@Index
@NotNull
@Email
@NonNull
@Getter
@Setter
private String email;
@Size(max = 50)
@Getter
@Setter
private String firstName;
@Size(max = 50)
@Getter
@Setter
private String lastName;
@Index
@Setter
@Getter
protected List<Key<Region>> regions;
}
我想做的是能够查询属于该用户区域列表中的区域的用户发送的所有 posts,并按顺序查询创作。
基本上,我试过这样做:
query = query.filter("sender.regions", "key").order("-creation");
当我第一次执行查询时,AppEngine 要求我创建这个索引:
<datastore-index kind="Post" ancestor="false" source="manual">
<property name="sender.regions" direction="asc"/>
<property name="creation" direction="desc"/>
</datastore-index>
但结果仍然毫无希望...如果有人有建议,我会很高兴。谢谢!
为了通过 "sender.regions" 查询 Post,应该嵌入发件人实体。
数据存储中没有 SQL 和 "join" 一样。您可以将发件人嵌入 post 或首先按区域查询发件人密钥,然后使用这些发件人密钥查询 Posts。
希望对您有所帮助。