如何从包含模型中过滤环回中的字段?
How to filter field in loopback from the include model?
我有这个查询:
UserModel.find({
filter: {
include:
[
"communications",
"roles"
],
where : {
"object_type" : 1
}
}
}, function(data){
$rootScope.users = data;
});
我想通过 "object_type" 字段从通信模型过滤器中获取所有数据,但它无法正常工作。
我的通信模型如下所示:
...
"properties": {
"object_type": {
"type": "number"
},
"object_id": {
"type": "number"
},
"communications_type_code": {
"type": "number"
},
"address_type": {
"type": "number"
},
"contact_value": {
"type": "string"
},
"notes": {
"type": "string"
},
....
Oded,我相信你不需要搜索参数中的filter
属性。它应该是这样的:
UserModel.find({
include: [ "communications", "roles" ],
where : { "object_type" : 1 }
}, function(data){
$rootScope.users = data;
});
还要确保您添加到 include
的其他实体与查询的模型有关系。真的 UserModel
还是应该 CommunicationsModel
?
要查询相关模型,您必须使用关系范围。在你的情况下会是这样的:
UserModel.find({
filter: {
include:
[
{
"relation": "communications",
"scope": {
"where": {"object_type": 1}
}
},
"roles"
]
}
}, function(data){
$rootScope.users = data;
});
的文档
我有这个查询:
UserModel.find({
filter: {
include:
[
"communications",
"roles"
],
where : {
"object_type" : 1
}
}
}, function(data){
$rootScope.users = data;
});
我想通过 "object_type" 字段从通信模型过滤器中获取所有数据,但它无法正常工作。
我的通信模型如下所示:
...
"properties": {
"object_type": {
"type": "number"
},
"object_id": {
"type": "number"
},
"communications_type_code": {
"type": "number"
},
"address_type": {
"type": "number"
},
"contact_value": {
"type": "string"
},
"notes": {
"type": "string"
},
....
Oded,我相信你不需要搜索参数中的filter
属性。它应该是这样的:
UserModel.find({
include: [ "communications", "roles" ],
where : { "object_type" : 1 }
}, function(data){
$rootScope.users = data;
});
还要确保您添加到 include
的其他实体与查询的模型有关系。真的 UserModel
还是应该 CommunicationsModel
?
要查询相关模型,您必须使用关系范围。在你的情况下会是这样的:
UserModel.find({
filter: {
include:
[
{
"relation": "communications",
"scope": {
"where": {"object_type": 1}
}
},
"roles"
]
}
}, function(data){
$rootScope.users = data;
});
的文档