简体   繁体   English

MotorEngine-如何在模型中表示外键的等效项?

[英]MotorEngine - How to represent the equivalent of the foreign key in model?

In MongoDB I have a document that represents a Balance which has an Stakeholder's ID as a field. 在MongoDB中,我有一个代表余额的文档,该文档具有一个涉众的ID作为字段。

I need to relate these two classes, Balance and Stakeholder, but I don't know what's the proper way. 我需要将这两个类(平衡和利益相关者)联系起来,但是我不知道什么是正确的方法。 I've seen there's a field that could be appropiate but I still don't understand it: EmbeddedDocumentField() 我已经看到有一个适当的字段,但我仍然不明白: EmbeddedDocumentField()

class Balance(Document):
    id = UUIDField()
    creation_date = DateTimeField(auto_now_on_insert=True)
    gross_balance = FloatField(required=True, min_value=0, default=0)
    balances_description = StringField(required=True, max_length=255)
    stake_holder = #FK to Stakeholder

class Stakeholder(Document):
    ...

Any idea? 任何想法?

如果涉stake_holder表示其他集合中的文档,而stake_holder是ObjectId,则应使用ReferenceField()

stake_holder = ReferenceField(reference_document_type=Stakeholder)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何找到破碎的“外键”关系的等价物? - How to Find the Equivalent of Broken “Foreign Key” Relationships? Motorengine(Mongo + Python):如何在另一个模型中引用一个模型? - Motorengine (Mongo + Python) : How do I reference a model inside another model? 猫鼬:如何建模外键/反向关系? - Mongoose: How to model a foreign key/inverse relationship? 相当于motorengine中的mongoengine.GeoPointField可以执行近距离查询? - What is the equivalent of mongoengine.GeoPointField in motorengine to perform near queries? 在这种情况下,什么相当于 mongdb 中的外键 - What is the equivalent of a foreign key in mongdb in this case 如何在 djongo 中引用嵌套模型 als 外键 - How to reference a nested model als foreign key in djongo 如何在Motorengine中创建具有Geopoint属性的Document类 - How do i create a Document class having geopoint property in motorengine 如何在ReactiveMongo模型中表示GeoJSON点? - How to represent a GeoJSON point in a ReactiveMongo model? 如何在模型/ dao接口中表示ID - How to represent an ID in model/dao interfaces 如何在 mongoengine class model 中将属性名称表示为日期时间 - How to represent a property name as datetime in mongoengine class model
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM