简体   繁体   English

使用Objectify,父项和子项进行查询

[英]Query with Objectify, parent and children

I wanted to know if I can make a query to a class father and his son in the same query. 我想知道是否可以在同一查询中查询班级父亲和儿子。

@Entity
public class Blog {
    @Getter
    @Setter
    @Id
    String id;

    @Getter
    @Setter
    int popularity;
}

@Entity
public class Post {
    @Id
    @Getter
    @Setter
    String id;

    @Getter
    @Setter
    String title;

    @Getter
    @Setter
    long published;

    @Getter
    @Setter
    String locale;

    @Getter
    @Setter
    @Load
    private Ref<Blog> parent; // or @Parent?

}

This would be possible? 这可能吗? -> - >

Query list type Post > filter locale "Post" > order published "Post" > order popularity "Blog" 查询列表类型“发布”>过滤区域设置“发布”>发布的订单“发布”> 订单受欢迎程度“博客”

Thanks. 谢谢。

No, you cannot. 你不能。 This would be a join, and app engine does not support joins in queries. 这将是一个联接,并且应用引擎不支持查询中的联接。 You either need to copy the data you want to filter on onto the Post entity, or else perform 2 separate queries and do the set intersection in memory. 您需要将要过滤的数据复制到Post实体上,或者执行2个单独的查询并在内存中进行设置的交集。

If you make the Ref field in Post a @Parent field, you can do an ancestor() query on the Blog and get everything (ancestor() includes the parent entity). 如果将“发布”中的“引用”字段设为@Parent字段,则可以在Blog上执行ancestor()查询并获取所有内容(ancestor()包括父实体)。 However, you will get literally everything in that entity group unless you filter by the type ie Post). 但是,除非您通过类型(即Post)进行过滤,否则您将获得该实体组中的所有内容。

This kind of micro-optimization is almost certainly pointless. 这种微优化几乎毫无意义。 It won't save you any money and it is unlikely to save you any noticeable latency, especially if you @Cache the Blog. 它不会为您节省任何金钱,也不太可能为您节省任何明显的延迟,尤其是如果您@Cache the Blog。

Of course you can! 当然可以! do this by adding the popularity field to Post. 为此,请将“流行度”字段添加到“邮政”中。 You'll have to update that value each day or week if the Blog's popularity changed. 如果Blog的流行程度发生变化,则每天或每周都必须更新该值。

This repetition of the information is typical and very common in noSql databases, don't think merise: think always: "the way to get all data ready for reading (in a minimal request count)", synchronizing data updates is very common in noSql dbs loke cassandra or datastore. 信息的重复是典型的,在noSql数据库中很常见,不要想那么多:永远想一想:“使所有数据准备就绪(以最少的请求计数)的方式进行读取”,在noSql中同步数据更新是很常见的dbs支持cassandra或数据存储。 Try reading some documentation on the subject 尝试阅读有关该主题的一些文档

@adevine you cannot say No! @adevine,你不能说不! if you don't know 如果你不知道

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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