PHP数据存储区(php-gds) - 访问实体引用

时间:2016-04-21 12:05:52

标签: php google-app-engine google-cloud-datastore

我获取了一个Project类型的实体。实体具有属性,该属性是实体类型User的关键。我想访问用户属性,但无法弄清楚如何操作。

这是我的代码:

$obj_store = new \GDS\Store('Project');
$project = $obj_store->fetchById($project_id);
echo $project->name // simple string property, works
echo $project->user->name // ?? doesn't work how do I access the user entity?

1 个答案:

答案 0 :(得分:1)

假设"用户"项目"项目"实体只是"用户"的字符串表示。实体ID,你会这样做:

$obj_store = new \GDS\Store('Project');
$project = $obj_store->fetchById($project_id);
echo $project->name // simple string property, works

$obj_user_store = new \GDS\Store('User');
$user = $obj_user_store->fetchById($project->user);
echo $user->name // simple string property, works