[英]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.