dousi6303
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?

图片转代码服务由CSDN问答提供 功能建议

我需要从父键获取子实体。 即使它可能,我也不知道。 但我尝试的如下:

  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); 
返回$ server_config_details; 
} 
   
  
 

 公共函数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; 
} 
   
 
 

但是 在上述两种情况下,它都没有给我任何回报。 你能告诉我我错过了什么吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • donglao9606
    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.

    点赞 评论

相关推荐