我有以下2个ndb模型
from endpoints_proto_datastore.ndb import EndpointsModel
class Foo(EndpointsModel):
attr1 = ndb.StringProperty(required=True)
class Bar(EndpointsModel):
attr1 = ndb.KeyProperty('Foo', required=True)
attr2 = ndb.KeyProperty('Foo', required=True)
正如您所看到的,Bar有几个与Foo相关的引用。
当我为每个引用分配值时,第二个引用替换了第一个引用,只有第二个引用存储到数据库中。最有趣的是,当使用dev_appserver数据存储查看器查找时,属性的名称是“Foo”,而不是替换第一个属性名称的第二个属性名称。
插入后,我期望的结果是这样的。
Bar(key=Key('Bar', xxxxxxxxxxxxxxxx), attr1=Key('Foo', xxxxxxxxxxxxxxxx), attr2=Key('Foo', xxxxxxxxxxxxxxxx)
但是我只得到了。
Bar(key=Key('Bar', xxxxxxxxxxxxxxxxxx), attr2=Key('Foo', xxxxxxxxxxxxxxxx))
在数据存储查看器中,
Entity Kind Bar
Entity Key xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ID xxxxxxxxxxxxxxxx
Foo (Key) xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Foo: id=xxxxxxxxxxxxxxxx