使用php-in-app引擎为实体设置数据存储父级


Set datastore parent for an entity using php in app engine

有人知道如何在php中为数据存储实体设置父级以建立层次结构吗?不幸的是,googlecloud仍然没有发布任何关于在php中使用数据存储的文档,这些文档使php变得无用,除了在web上发布一篇博客文章之外,没有其他资源。

我刚刚发布了PHP数据存储库的第一个版本,这让这一切变得非常简单。

https://github.com/tomwalder/php-gds

"examples"文件夹中有一些代码示例,但看起来有点像(我将跳过样板)。。。

// Grab the parent Entity from Datastore
$obj_will_shakespeare = $obj_author_store->fetchOne();
// Create the child
$obj_book = new GDS'Entity();
$obj_book->title = 'Romeo and Juliet';
$obj_book->isbn = '1840224339';
// Set the parent 
$obj_book->setAncestry($obj_will_shakespeare);
// Write the child to Datastore
$obj_book_store->upsert($obj_book);

此语法还支持多级嵌套。