简体   繁体   中英

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.

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). However, you will get literally everything in that entity group unless you filter by the type ie 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.

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.

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. Try reading some documentation on the subject

@adevine you cannot say No! if you don't know

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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