toDatastoreKey method
Key
toDatastoreKey(
- Key dbKey
)
override
Converts a Key to a ds.Key.
Implementation
@override
ds.Key toDatastoreKey(Key dbKey) {
var elements = <ds.KeyElement>[];
var currentKey = dbKey;
while (!currentKey.isEmpty) {
var id = currentKey.id;
var modelDescription = _modelDescriptionForType(currentKey.type)!;
var kind = modelDescription.kindName(this);
var useIntegerId = modelDescription.useIntegerId;
if (useIntegerId && id != null && id is! int) {
throw ArgumentError('Expected an integer id property but '
'id was of type ${id.runtimeType}');
}
if (!useIntegerId && (id != null && id is! String)) {
throw ArgumentError('Expected a string id property but '
'id was of type ${id.runtimeType}');
}
elements.add(ds.KeyElement(kind, id));
currentKey = currentKey.parent!;
}
var partition = currentKey._parent as Partition;
return ds.Key(elements.reversed.toList(),
partition: ds.Partition(partition.namespace));
}