@
ayanamist 源码摆在SDK里,你自己看看就知道了:
@
classmethod def get_by_id(cls, ids, parent=None, **kwargs):
"""Get instance of Model class by id.
Args:
key_names: A single id or a list of ids.
parent: Parent of instances to get. Can be a model or key.
config: datastore_rpc.Configuration to use for this request.
"""
config = datastore._GetConfigFromKwargs(kwargs)
if isinstance(parent, Model):
parent = parent.key()
ids, multiple = datastore.NormalizeAndTypeCheck(ids, (int, long))
keys = [datastore.Key.from_path(cls.kind(), id, parent=parent)
for id in ids]
if multiple:
return get(keys, config=config)
else:
return get(keys[0], config=config)
一个实体在存储到datastore的时候,最多需要保存到3种类型的表,但没有任何一种表的任何一个字段是其id或key name,所有的表都只存储编码后的key。这就是为什么不可能不用key来获取实体的原因。
顺带一提,即使是query,也是查询索引表或自定义索引表,获得key,然后再到实体表获取key对应的实体。