我需要从父级的密钥中获取子实体。即使它可能,我也不知道。但我尝试的是如下:
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;
}
和
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;
}
但在上述两种情况下,它都没有给我任何回报。你能告诉我我错过了什么吗?
答案 0 :(得分:3)
您可以使用祖先查询来查找子实体:
例如,此查询:
SELECT Floor WHERE __key__ HAS ANCESTOR KEY(Building, 'C')
将返回根实体的Floor
种类的所有子实体,其种类为Building
,名称为C
:
[Building:C, Floor:1]
[Building:C, Floor:2]
查询(与查询相对)要求您提前知道完整密钥,因此无法使用它们来查找根实体的子实体。