App Engine,两个实体之间的交叉引用
我希望有两种类型的实体相互引用。 但Python还不知道第一个实体类中第二个实体类的名称。 那么我该如何编码。
class Business(db.Model):
bus_contact_info_ = db.ReferenceProperty(reference_class=Business_Info)
class Business_Info (db.Model):
my_business_ = db.ReferenceProperty(reference_class=Business)
如果您建议仅在一个中使用引用并使用隐式创建的属性 (这是一个查询对象)在其他中。 然后我质疑使用查询与直接使用 get() 键的 CPU 配额惩罚
请建议如何在 python 中编写此代码
i will like to have two types of entities referring to each other.
but python dont know about name of second entity class in the body of first yet.
so how shall i code.
class Business(db.Model):
bus_contact_info_ = db.ReferenceProperty(reference_class=Business_Info)
class Business_Info (db.Model):
my_business_ = db.ReferenceProperty(reference_class=Business)
if you advice to use reference in only one and use the implicitly created property
(which is a query object) in other.
then i question the CPU quota penalty of using query vs directly using get() on key
Pleas advise how to write this code in python
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查询速度稍慢,因此确实使用了更多资源。 ReferenceProperty 不需要参考类。因此,您始终可以像这样定义业务:
您的数据结构也可能有更好的选择。请查看建模关系一文,了解一些想法。
这是一对一的映射吗?如果这是一对一的映射,您最好对数据进行非规范化。
它会改变吗?如果不是(并且是一对一的),也许您可以使用实体组并构建数据,以便您可以直接使用键/键名称。您可以通过将 BusinessInfo 设为 Business 的子项,然后始终使用“i”作为 key_name 来实现此目的。例如:
Queries are a little slower, and so they do use a bit more resources. ReferenceProperty does not require reference_class. So you could always define Business like:
There may also be better options for your datastructure too. Check out the modelling relationships article for some ideas.
Is this a one-to-one mapping? If this is a one-to-one mapping, you may be better off denormalizing your data.
Does it ever change? If not (and it is one-to-one), perhaps you could use entity groups and structure your data so that you could just directly use the keys / key names. You might be able to do this by making BusinessInfo a child of Business, then always use 'i' as the key_name. For example: