我怎样才能查询直接后代? [英] How can I query for direct descendants only?

查看:112
本文介绍了我怎样才能查询直接后代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有实体a,b和c都是同一类型,情况如下所示:

实体a是实体b $ b的父类$ b实体b是实体c的父代



现在,如果我执行以下查询

  query = ndb.Query(ancestor = a.key)
result = query.fetch()

结果将包含b和c实体。有没有一种方法可以过滤c,以便只有直系后代的实体依然存在?任何方式除了我通过结果,并删除他们我的意思是。

解决方案

唯一的方法是修改您的添加一个引用实体的直接父项的'父' KeyProperty ,然后过滤。


Let's say I have entities a, b and c all of the same type, and the situation is like this:

entity a is parent for entity b entity b is parent for entity c

Now if I do the following query

query = ndb.Query(ancestor=a.key)
result = query.fetch()

The result will contain both b and c entities. Is there a way I can filter out c so that only entities that are direct descendants remain? Any way apart from me going through the results and removing them I mean.

解决方案

The only way to do this is to modify your schema, adding a 'parent' KeyProperty that references an entity's direct parent, then filtering on that.

这篇关于我怎样才能查询直接后代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆