allocateIdsToEntities() public method

Any incomplete keys will be allocated an ID. Named keys in the input will remain unchanged.
public allocateIdsToEntities ( array $entities ) : Entity[]
$entities array A list of entities
return Entity[]
 /**
  * Insert multiple entities
  *
  * No service requests are run when this method is called.
  * Use {@see Google\Cloud\Datastore\Transaction::commit()} to commit changes.
  *
  * Example:
  * ```
  * $entities = [
  *     $datastore->entity('Person', ['firstName' => 'Bob']),
  *     $datastore->entity('Person', ['firstName' => 'John'])
  * ];
  *
  * $transaction->insertBatch($entities);
  * $transaction->commit();
  * ```
  *
  * @param Entity[] $entities The entities to insert.
  * @return Transaction
  */
 public function insertBatch(array $entities)
 {
     $entities = $this->operation->allocateIdsToEntities($entities);
     foreach ($entities as $entity) {
         $this->mutations[] = $this->operation->mutation('insert', $entity, Entity::class);
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * Insert multiple entities
  *
  * No service requests are run when this method is called.
  * Use {@see Google\Cloud\Datastore\Transaction::commit()} to commit changes.
  *
  * Example:
  * ```
  * $entities = [
  *     $datastore->entity('Person', ['firstName' => 'Bob']),
  *     $datastore->entity('Person', ['firstName' => 'John'])
  * ];
  *
  * $transaction->insertBatch($entities);
  * $transaction->commit();
  * ```
  *
  * @param Entity[] $entities The entities to insert.
  * @return Transaction
  */
 public function insertBatch(array $entities)
 {
     $entities = $this->operation->allocateIdsToEntities($entities);
     $this->operation->mutate('insert', $entities, Entity::class);
     return $this;
 }
 /**
  * Insert multiple entities
  *
  * Any entity with incomplete keys will be allocated an ID prior to insertion.
  *
  * Insert by this method is non-transactional. If you need transaction
  * support, use {@see Google\Cloud\Datastore\Transaction::insertBatch()}.
  *
  * Example:
  * ```
  *
  * $entities = [
  *     $datastore->entity('Person', ['firstName' => 'Bob']),
  *     $datastore->entity('Person', ['firstName' => 'John'])
  * ];
  *
  * $datastore->insertBatch($entities);
  * ```
  *
  * @param Entity[] $entities The entities to be inserted.
  * @param array $options [optional] Configuration options.
  * @return array [Response Body](https://cloud.google.com/datastore/reference/rest/v1/projects/commit#response-body)
  */
 public function insertBatch(array $entities, array $options = [])
 {
     $entities = $this->operation->allocateIdsToEntities($entities);
     $mutations = [];
     foreach ($entities as $entity) {
         $mutations[] = $this->operation->mutation('insert', $entity, Entity::class);
     }
     return $this->operation->commit($mutations, $options);
 }