我在 settings.py 中定义了以下资源,
builds = {
'item_title': 'builds',
'schema': {
'sources': {
'type': 'list',
'schema': {
'type': 'objectid',
'data_relation': {
'resource': 'sources',
'embeddable': True,
}
}
},
'checkin_id': {
'type': 'string',
'required': True,
'minlength': 1,
},
}
}
当我尝试根据值为 objectid 的成员进行过滤时,我得到空列表。
http://127.0.0.1:5000/builds?where={"sources":"54e328ec537d3d20bbdf2ed5"}
54e328ec537d3d20bbdf2ed5 是源的 id
有办法做到这一点吗?
假设您确实拥有,您的查询应该可以正常工作54e328ec537d3d20bbdf2ed5
值包含在任何sources
任何内的字段builds
文档。
我的意思是,你不能查询builds
文档存在的端点sources
端点(您当然可以在sources
端点。)但是,如果您实际上存储了builds文档及其引用sources文档,那么您的查询将正常工作,因为您实际上要问的是“让我全部builds与此相关的文件sources文档”。例如,如果您将这样的文档发布到builds
端点:
{
"sources": ["54e328ec537d3d20bbdf2ed5"]
"checkin_id": "A"
}
然后这个查询:
http://127.0.0.1:5000/builds?where={"sources":"54e328ec537d3d20bbdf2ed5"}
将返回该一份文件。当然,既然你定义了sources
作为可嵌入的,你还可以这样做:
http://127.0.0.1:5000/builds?where={"sources":"54e328ec537d3d20bbdf2ed5"}&embedded={"sources":1}
这将使您引用的文档与任何匹配的文档一起嵌入,如下所示:
{
"sources": [{"field1": "hey", "field2":"I'm an embedded source"}]
"checkin_id": "A"
}
而您会得到一个没有显式嵌入的“原始”文档。可能值得一提的是,您还可以启用预定义嵌入 http://python-eve.org/features#predefined-resource-serialization引用的资源,因此您的客户不必明确请求嵌入。
希望这可以帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)