dsfdfdfd6576578 2016-10-07 14:04
浏览 13

与共同祖先检索不同种类的实体

I want to store hierarchical entities in the datastore. The children entities would have different kind, to represent something like this :

type EntityA struct {
    Id        string
    LeafA     *EntityA
    LeafB     *EntityB
    SomeValue string
}

type EntityB struct {
    Id         string
    OtherValue string
}

I planned to use ancestors, but it seems impossible to retrieve the children of a common ancestor that have different kind.

To retrieve the whole parent, is it possible to query all children of a common ancestors without specifying the kind ?

Or is there another possibility to solve this problem ?

  • 写回答

1条回答 默认 最新

  • dtoaillwk759656786 2016-10-07 15:17
    关注

    From Using ancestor paths:

    The complete key identifying the entity consists of a sequence of kind-identifier pairs specifying its ancestor path and terminating with those of the entity itself:

    [Person:GreatGrandpa, Person:Grandpa, Person:Dad, Person:Me]
    

    For a root entity, the ancestor path is empty and the key consists solely of the entity's own kind and identifier:

    [Person:GreatGrandpa]
    

    In other words the key of any of the entities in an entity group (including the root entity - the common ancestor) is a list of keys for the entire ancestry path, which starts with the root entity's key.

    So, to obtain the root entity key from any of the descendants just get the 1st element in that entity's key list.

    Not familiar with go, but in python a particular item in the ancestry path is a tuple (pair) and to obtain the root entity key from any entity key it'd be something like this:

    root_entity_key = ndb.Key(pairs=tuple(list(entity_key.pairs())[0])
    

    Now, with the root entity (common ancestor) key you can perform ancestor queries for any descendant kind you desire.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题