Google\Cloud\Datastore\Operation::key PHP Method

key() public method

Create a single Key instance
See also: https://cloud.google.com/datastore/reference/rest/v1/Key Key
See also: https://cloud.google.com/datastore/reference/rest/v1/Key#PathElement PathElement
public key ( string $kind, string | integer $identifier = null, array $options = [] ) : Key
$kind string The kind.
$identifier string | integer [optional] The ID or name.
$options array [optional] { Configuration Options @type string $identifierType If omitted, type will be determined internally. In cases where any ambiguity can be expected (i.e. if you want to create keys with `name` but your values may pass PHP's `is_numeric()` check), this value may be explicitly set using `Key::TYPE_ID` or `Key::TYPE_NAME`. }
return Key
    public function key($kind, $identifier = null, array $options = [])
    {
        $options += ['namespaceId' => $this->namespaceId];
        $key = new Key($this->projectId, $options);
        $key->pathElement($kind, $identifier, $options);
        return $key;
    }

Usage Example

 public function testKeyWithNamespaceIdOverride()
 {
     $op = new Operation($this->connection->reveal(), 'foo', 'namespace', $this->mapper);
     $key = $op->key('Person', 'Bob', ['namespaceId' => 'otherNamespace']);
     $obj = $key->keyObject();
     $this->assertEquals('otherNamespace', $obj['partitionId']['namespaceId']);
 }
All Usage Examples Of Google\Cloud\Datastore\Operation::key