【问题标题】:About the relationship in two entities关于两个实体中的关系
【发布时间】:2013-02-28 14:18:20
【问题描述】:

我正在考虑创建一个属性来存储其他实体的密钥或 ID 作为对该实体的引用。
我想知道两件事。
1.属性应该存储哪些数据,key还是ID?
2.房产的类型应该是什么?也许是 StringProperty?

【问题讨论】:

    标签: google-app-engine google-cloud-datastore bigtable


    【解决方案1】:

    Datastore 对此有一个特殊的属性类型:ReferenceProperty。有两种使用方式。

    一个:

    someothermodel = db.ReferenceProperty()
    

    两个:

    someotherspecificmodel = db.ReferenceProperty(SomeModel)
    

    在示例 2 中,只能分配类型为 SomeModel 的模型,在示例 1 中,可以分配任何模型。

    ReferenceProperty的值类型是db.Key

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-27
      • 1970-01-01
      相关资源
      最近更新 更多