Angularjs 如何从包含模型中筛选环回中的字段?
我有一个疑问:Angularjs 如何从包含模型中筛选环回中的字段?,angularjs,loopbackjs,Angularjs,Loopbackjs,我有一个疑问: UserModel.find({ filter: { include: [ "communications", "roles" ], where : { "object_type" : 1 } } }, 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"
},
....
UserModel.find({
include: [ "communications", "roles" ],
where : { "object_type" : 1 }
}, function(data){
$rootScope.users = data;
});
Oded,我相信您不需要搜索参数中的
filter
属性。应该是这样写的:
...
"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"
},
....
UserModel.find({
include: [ "communications", "roles" ],
where : { "object_type" : 1 }
}, function(data){
$rootScope.users = data;
});
还要确保添加到
中的其他实体包括
与查询的模型有关系。是真的UserModel
还是应该是communicationmodel
?要查询相关模型,您必须使用关系范围。在您的情况下,可能是这样的:
UserModel.find({
filter: {
include:
[
{
"relation": "communications",
"scope": {
"where": {"object_type": 1}
}
},
"roles"
]
}
}, function(data){
$rootScope.users = data;
});
检查有关的文档