您好,我似乎错过了一些有关Loopback where子句或语法的信息。我的问题是,如果我尝试获取匹配模型实例的列表,我会收到一个空数组,如果在loopback api explorer或者trhough http api请求中没有区别。
我的主题"模型:
{
"user": "59eef907cc199c1cf8f99296",
"semester": "59eef6f8ebf12e1a37ee898b",
"subject_name": "Mathematik",
"subject_relevance": "1",
"subject_details": "",
"id": "59eef96aebf12e1a37ee898f"
}
一个主题实例:
{"where" : {"semester" : "59eef6f8ebf12e1a37ee898b"}}
My Loopback API Explorer过滤器:
http://localhost:3000/api/subjects?filter[where][semester]=59eef6f8ebf12e1a37ee898b
我的http请求:
[]
我收到的结果:
{"where" : {"subject_name" : "Mathematik"}}
如果我尝试搜索此内容:
http://localhost:3000/api/subjects?filter[where][subject_name]=Mathematik
或在浏览器中:
wizard = fields.One2many('product.gold','service',change_default=True, default=_onchange_action_product_add)
@api.onchange('product_id')
def _onchange_action_product_add(self):
res = self.product_id.product_pack
r = []
value = {}
for var in self.product_id.product_pack:
print "var:::", var
for line in self.product_id.product_pack:
print "line:::", line , line.product_id, line.product_id.name, line.qty, line.services, line.id
data = {'products_ids': line.product_id.id,
'service':var.id, #many2one child field from one2many field
'services':line.services,
'qtyy': line.qty
}
print "data:", data
r.append((0, 0, data))
print "r.append", r.append, r
#return data
value.update(wizard=r)
return {'value': value}
我正确或正常地接受了实例。所以我去了documentation,我找到了解决问题的一些提示或解决方案。有人可以帮助我或建议我找一些正确的实例吗?我错过了什么吗?它有没有这些是ID字段或它是什么?
感谢您提前提供任何帮助!!
答案 0 :(得分:1)
有两种方法可以根据where子句获取记录
一个是通过使用'findOne'方法
获取请求
http://localhost:3000/api/subjects/findOne?filter[where][semester]=59eef6f8ebf12e1a37ee898b
其他人正在使用正常的获取请求
http://localhost:3000/api/subjects?filter={"where":{"semester":"59eef6f8ebf12e1a37ee898b"}}
答案 1 :(得分:0)
我正在使用环回4,但遇到了同样的问题。
Here is the issue in loopback git
解决方案是在您的@model装饰器中添加此设置
@model({settings: {"strict":false, "strictObjectIDCoercion": true}})