GAE结构模型没有非规范化

时间:2013-02-11 20:17:45

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

我正在尝试重新构建Google App Engine的关系数据库,我遇到了以一种方式建模一组关系的问题,这种方式可以让我以有效的方式查询我需要的数据。

作为一个人为的例子,我说我有以下模型:

class Rental(db.Model):
    # ancestor of one or more RentalDatas
    date = db.DateProperty()
    location = db.IntegerProperty()
    # + customer, etc

class RentalData(db.Model):
    # a Rental is our parent
    unicorn = db.ReferenceProperty(Unicorn, collection_name='rentals')
    mileage_in = db.FloatProperty()
    mileage_out = db.FloatProperty()
    # + returned_fed, etc

class Unicorn(db.Model):
    name = db.StringProperty()
    color = db.IntegerProperty()
    # 'rentals' collection from RentalData

每次租借都可以包含多个独角兽,所以如果我能提供帮助,我宁愿不要将RentalRentalData模型结合起来。我几乎总是从一个给定的Unicorn开始,我希望能够查询,比如说,独角兽是否在最后一次 x 租借时返回,而没有迭代独角兽的RentalData集合中的每个rentals并查询父节点,只是为了获得排序日期。

我是否只需咬紧牙关并取消正常化?我尝试在date中复制RentalData,并在需要属性时根据需要使用parent()获取相应的Rental。它有效,但我担心我只是采取简单的方法。

0 个答案:

没有答案