GAE 建模关系选项

发布于 2024-08-27 13:11:09 字数 810 浏览 8 评论 0原文

我需要对以下情况进行建模,但我似乎找不到 关于如何为谷歌应用程序“正确”执行此操作的一致示例 引擎。

假设我遇到如下简单情况:

Company 1 -----> M Store

一家公司拥有一对多商店。每个商店都有一个地址,由以下组成 地址行 1、城市、州、国家、邮政编码等。

好的。假设我们需要创建一个“审计”。审计是为了 公司,并且可以进行一对多的凝视。

就像这样:

Audit 1 ------> 1 Company
      1 ------> M Store

现在我们需要根据商店查询所有“审核” “地址”,以便将“审计员”派往正确的地点。

类似这样的文章似乎有很多:

http://code.google.com/ appengine/articles/modeling.html

其中给出了创建“ContactCompany”模型类的示例。 然而他们也说你应该利用这种关系 仅当您“确实需要”并且“关心”性能时。

我还经常读到,你应该尽可能多地非规范化 从而将所有“可查询”数据移至审计中 班级。

那么您建议解决这个问题的最佳方法是什么?

我看到有一个 Expando 类,但我不确定这是否是 对此的“最佳”选择。

对此的任何帮助或想法将不胜感激。

提前致谢, 马特

I need to model the following situation and I can't seem to find a
consistent example on how to do it "correctly" for the google app
engine.

Suppose I've got a simple situation like the following:

Company 1 -----> M Store

A company has one to many stores. Each store has an address made up of
a address line 1, city, state, country, postcode etc.

Ok. Lets say we need to create say an "Audit". An Audit is for a
company and can be across one to many stares.

So something like:

Audit 1 ------> 1 Company
      1 ------> M Store

Now we need to query all of the "audits" based on the Store
"addresses" in order to send the "Auditors" to the right locations.

There seem to be numerous articles like this one:

http://code.google.com/appengine/articles/modeling.html

Which give examples of creating a "ContactCompany" model class.
However they also say that you should use this kind of relationship
only when you "really need to" and with "care" for performance.

I've also read - frequently - that you should denormalize as much as
possible thereby moving all of the "query-able" data into the Audit
class.

So what would you suggest as the best way to solve this?

I've seen that there is an Expando class but I'm not sure if that is
the "best" option for this.

Any help or thoughts on this would be totally appreciated.

Thanks in advance,
Matt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生漫 2024-09-03 13:11:09
class Company(db.Model):
   name = db.StringProperty()

class address(db.Model):
   address = db.PostalAddressProperty()

class store(db.Model):
   company = db.ReferenceProperty(Company)
   address = db.ReferenceProperty(Address)

现在您可以查询所有公司商店,

company_oject.address_set.all().filter().fetch()

除非是拥有数千家商店的跨国公司,否则此查询在大多数情况下应该可以正常工作。

http://code.google.com/appengine/docs/ python/datastore/entitiesandmodels.html#References

进一步提供帮助。

class Company(db.Model):
   name = db.StringProperty()

class address(db.Model):
   address = db.PostalAddressProperty()

class store(db.Model):
   company = db.ReferenceProperty(Company)
   address = db.ReferenceProperty(Address)

now you can query for all company store by,

company_oject.address_set.all().filter().fetch()

unless it is MNC with thousands of store, this query should work fine in most cases.

http://code.google.com/appengine/docs/python/datastore/entitiesandmodels.html#References

helps further.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文