【问题标题】:Foreign Key in NDB/Google App EngineNDB/Google App Engine 中的外键
【发布时间】:2014-07-19 20:25:08
【问题描述】:

我正在使用 Google App Engine 中的 NDB 构建一个带有 Google Endpoints 和 Datastore 的网络应用程序。每个登录的用户都有一组“关注列表”,这只是 NDB 扩展模型中的重复属性,如下所示:

类用户(ndb.Expando):

username = ndb.StringProperty()
email = ndb.StringProperty()
password = ndb.StringProperty()
overallRanking = ndb.IntegerProperty()
numRankings = ndb.IntegerProperty()
watchedListings = ndb.KeyProperty(modelListing,repeated=True)

如您所见,我正在存储模型列表实体的键。但是,当我删除一个 modelListing 时,我希望它自动删除所有在其 watchListings 对象中拥有该键的用户的键。这类似于 SQL 如何处理外键。有没有办法做到这一点,而无需遍历数据库中的所有用户并搜索该密钥、删除它并执行 put()?

【问题讨论】:

    标签: python google-app-engine


    【解决方案1】:

    我确实尝试过这个功能。看起来您可以使用以下方法完成这项工作: https://developers.google.com/appengine/docs/python/ndb/entities?hl=nl#hooks

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多