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

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

问题描述

我正在尝试围绕 gae 数据存储,但我不完全理解 关键类的文档/或者可能是我不了解的一般祖先关系.我认为我想要的是多个祖先.

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. 个人资料(可以是跑步者和赞助商)
  2. 跑步(定义谁(参见个人资料)为什么慈善机构跑步,实际完成的回合)
  3. 赞助(定义谁(参见个人资料)为什么跑步捐赠了多少,捐赠是否已经完成)

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

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.我想轻松查询一个人所做的所有赞助以及属于某个跑步的所有赞助.所以,我觉得,这应该是合适的:

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

这样合理吗?我可以看到一个 构造函数按祖先顺序排列的几种作为参数.是为这种情况设计的吗?运行"和配置文件"将处于同一级别"(即妈妈和爸爸的祖先而不是父亲和祖父)——那个构造函数在 python 中会是什么样子?

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.

例如:

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()

祖先只是将实体放在同一个实体组中(这可能非常有限!),同时在模型已经建立的关系之上强制附加关系.请参阅交易和实体组,可能还有Google App Engine 中的争用问题.

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 Documentation 或者说是祖先关系吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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