dousi6303 2017-01-20 13:52
浏览 48
已采纳

如何通过祖先密钥数据存储区获取实体?

I need to get a sub entity from the key of parent. I dont know even if its possible. But what I tried is as following:

public function get_service_details(){
     $datastore = new Google\Cloud\Datastore\DatastoreClient(['projectId' => $this->config->item('google_project_id')]);
     $key = $datastore->key($this->entity_kind);

     $key->ancestor($this->parent_kind, $this->parent_key);
     $server_config_details = $datastore->lookup($key);
     return $server_config_details;
}

and

public function get_service_details(){
     $datastore = new Google\Cloud\Datastore\DatastoreClient(['projectId' => $this->config->item('google_project_id')]);
     $ancestorKey = $datastore->key($this->parent_kind, $this->parent_key);
     $query = $datastore->query()
        ->kind($this->entity_kind)
        ->hasAncestor($ancestorKey);

     $server_config_details = $datastore->runQuery($query);
     return $server_config_details;
}

But in both of the above cases it returned me nothing. Can you please tell me what am I missing?

  • 写回答

1条回答 默认 最新

  • donglao9606 2017-01-23 01:41
    关注

    You can use an ancestor query to find child entities:

    For example, this query:

    SELECT Floor WHERE __key__ HAS ANCESTOR KEY(Building, 'C')
    

    will return all child entities of kind Floor of the root entity with kind Building and name C:

    [Building:C, Floor:1]
    [Building:C, Floor:2]
    

    Lookups (as opposed to queries) require that you know the full key ahead of time, so they can't be used to find child entities of a root entity.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥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时遇到的编译问题