1

私はgoogle datastoreに取り組んでいます。私はuserエンティティを親として持つLog種類のエンティティを作成する必要があります。私はPHPでAPIを統合するためにGoogle-api-php-clientライブラリを使用しています。私はエンタテイメントの作成に成功しています。エンティティを挿入するには、次の関数を使用しています。phpを使用してエンティティ(Googleデータストア)の祖先を作成するにはどうすればよいですか?

/* 
*Function to insert the entity into the google datastore. 
*/ 
function google_set_insert($data) { 

    $field_set = $data['field_set']; 
    $entity_kind = $data['entity_kind']; 
    $entity_name = $data['entity_name']; 

    $entity = google_create_entity($field_set, $entity_kind, $entity_name); 
    $mutation = new Google_Service_Datastore_Mutation(); 
    $mutation->setInsert($entity); 
    $req = new Google_Service_Datastore_CommitRequest(); 
    $req->setMode('NON_TRANSACTIONAL'); 
    $req->setMutations($mutation); 
    return $req; 
} 

しかし、エンティティの祖先を作成できません。私が逃していることを教えてもらえますか?

答えて

0

Google Cloud PHPクライアントライブラリを使用することをおすすめします(GAE標準に準拠していない限り)。

最初にエンティティを作成するときは、そのエンティティを最初に書き込むと変更できないため、エンティティを追加する必要があります。

use Google\Cloud\Datastore\DatastoreClient; 

$datastore = new DatastoreClient(); 

$key = $datastore->key('Person', 'Bob'); 
$key->ancestor('Parents', 'Joe'); 
$entity = $datastore->entity($key, [ 
    'firstName' => 'Bob', 
    'lastName' => 'Testguy' 
]); 

echo $entity['firstName']; // 'Bob' 
$entity['location'] = 'Detroit, MI'; 

詳細はkeysのドキュメントを参照してください。

+0

GAE標準では、祖先をサポートするPHP-GDSライブラリを使用できます。 https://github.com/tomwalder/php-gds – Tom

関連する問題