NDB/Google App Engine中的外键
我正在用Google Endpoints和Datastore在Google App Engine上构建一个网页应用。每个登录的用户都有一组“关注的列表”,这其实就是NDB的扩展模型中的一个重复属性,像这样:
class user(ndb.Expando):
username = ndb.StringProperty()
email = ndb.StringProperty()
password = ndb.StringProperty()
overallRanking = ndb.IntegerProperty()
numRankings = ndb.IntegerProperty()
watchedListings = ndb.KeyProperty(modelListing,repeated=True)
如你所见,我在存储modelListing实体的键。不过,当我删除一个modelListing时,我希望能够自动删除所有用户在他们的watchedListings对象中对应的键。这有点像SQL处理外键的方式。有没有办法做到这一点,而不需要遍历数据库中的所有用户,查找那个键,然后删除它,再执行put()操作呢?
1 个回答
0
我还没有尝试这个功能。看起来你可以通过以下链接来完成这个工作:https://developers.google.com/appengine/docs/python/ndb/entities?hl=nl#hooks