你能帮我理解nbd Key Class文档还是祖先关系? [英] Can you help me understand the nbd Key Class Documentation or rather ancestor relationship?

查看:126
本文介绍了你能帮我理解nbd Key Class文档还是祖先关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图将我的头包裹在gae数据存储区中,但我不完全了解关键类文档 /或者它可能是我一般不了解的祖先关系。
我认为我想要的是多个祖先。例如:
假设我想模拟我们学校举办慈善活动的年度赞助;学校的孩子们绕着赛道跑来跑去,他们的亲戚们(=赞助商)每轮都向慈善机构捐款。



在我看来,我会创建以下几种:


  1. 可以是跑步者和赞助商)

  2. 运行(定义谁(cf. profile)为慈善事业运行,实际完成轮次)
  3. 赞助(定义谁(cf. profile)捐出了多少钱,捐赠是否已完成)

我了解到数据存储区是一个nosql,非关系型数据库,但还没有完全掌握它。所以我的问题是:

a。是否为赞助创建实体,甚至是数据存储的最佳方式?我也可以将它建模为一种有关系(每场比赛都有赞助商) - 但由于我也想跟踪赞助金额,无论赞助商是否支付了费用,可能还有更多,这似乎是不适当的



。我想很容易地查询所有由一个人发起的赞助以及属于某一运行的所有赞助。
所以,我觉得,这是适当的:

 个人资料 - 是 - >的祖先。运行
配置文件 - 是 - >的始祖赞助
运行 - 是 - >的始祖赞助

这是否合理?
我可以看到构造函数一个按照祖先顺序作为参数的密钥。是为这种情况设计的吗? 运行和配置文件将处于相同的等级(即妈妈和父亲祖先而不是父亲和祖父) - 该构造函数在python中的外观是什么?

解决方案

在实体之间建立关系的主要方式是通过实体模型中的关键属性。通常不需要祖先。



例如:

  class Profile (ndb.Model):
name = ndb.StringProperty()

class Run(ndb.Model):
runner = ndb.KeyProperty(kind ='Profile')
rounds = ndb.IntegerProperty()
赞助= ndb.KeyProperty(kind ='赞助')

赞助(ndb.Model):
run = ndb。 KeyProperty(kind ='Run')
donor = ndb.KeyProperty(kind ='Profile')
done = ndb.BooleanProperty()

祖先只是将实体放置在同一个实体组中(这可能是相当有限的!),同时在已经建立的关系之上执行附加关系由模型。请参阅交易和实体组,也许 Google App Engine中的争用问题


I am trying to wrap my head 'round gae datastore, but I do not fully understand the documentation for the Key Class / or maybe it is ancestor relationships in general I do not grasp. I think what I want is multiple ancestors.

Example: Say I wanted to model our school's annual sponsored run for charity; school kids run rounds around the track and their relatives (=sponsors) donate to charity for each round completed.

In my mind, I would create the following kinds:

  1. Profile (can be both runner and sponsor)
  2. Run (defines who (cf. profile) runs for what charity, rounds actually completed)
  3. Sponsorship (defines who (cf. profile) donates how much for what run, whether the donation has been made)

I've learned that datastore is a nosql, non-relational database, but haven't fully grasped it. So my questions are:

a. Is creating an entity for "Sponsorship" even the best way in datastore? I could also model it as a has-a relationship (every run has sponsors) - but since I also want to track the amount sponsored, whether sponsor paid up and maybe more this seems inappropriate

b. I'd like to easily query all sponsorhips made by a single person and also all sponsorships belonging to a certain run. So, I feel, this would be appropriate:

Profile --is ancestor of--> Run
Profile --is ancestor of--> Sponsorship
Run --is ancestor of--> Sponsorship

Is that sensible? I can see a constructor for a Key that takes several kinds in ancestor order as arguments. Was that designed for this case? "Run" and "profile" would be at the same "level" (i.e. mum&dad ancestors not father&grandfather) - what would that constructor look like in python?

解决方案

The primary way of establishing relationships between entities is via the key properties in the entity model. Normally no ancestry is needed.

For example:

class Profile(ndb.Model):
    name = ndb.StringProperty()

class Run(ndb.Model):
    runner = ndb.KeyProperty(kind='Profile')
    rounds = ndb.IntegerProperty()
    sponsorship = ndb.KeyProperty(kind='Sponsorship')

class Sponsorship(ndb.Model):
    run = ndb.KeyProperty(kind='Run')
    donor = ndb.KeyProperty(kind='Profile')
    done = ndb.BooleanProperty()

The ancestry just places entities inside the same entity group (which can be quite limiting!) while enforcing additional relationships on top of the ones already established by the model. See Transactions and entity groups and maybe Contention problems in Google App Engine.

这篇关于你能帮我理解nbd Key Class文档还是祖先关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆