【发布时间】:2018-05-22 19:41:54
【问题描述】:
我在我的项目中使用pymodm 作为 ORM。
我有以下简单案例:
class IdentityRecord(MongoModel):
alias = fields.CharField() # normal name for identity
class IdentityImage(MongoModel):
filename = fields.CharField() # filename on filesystem
source_identity = fields.ReferenceField(IdentityRecord) # reference to an identity
我们可以看到,每个IdentityImage 都指向IdentityRecord。
如果我有对象IdentityRecord,那么如何从IdentityImage 中找到所有在python 代码中引用该对象的记录?
当然,我可以做到以下几点:
IdentityImage.objects.raw({'source_identity': identity.pk})
但是,用户 'source_identity' 字符串文字的必要性有点违背了 ORM 的目的。在这个框架中有什么方法可以通过使用IdentityRecord 对象的实例来查询IdentityImage 集合吗?
【问题讨论】:
-
您好,您找到解决方案了吗?
-
嗨。我还没有找到这个特定问题的解决方案。对不起:(
标签: mongodb python-3.x orm pymongo pymodm