我有一个环回模型客户,我想从android中的客户模型实例访问相关模型订单。但是,我无法找到有关此问题的任何文件。有人可以帮我吗?
提前致谢!
{
"name": "customer",
"plural": "customers",
"base": "User",
"properties": {
"phoneVerified": {
"type": "boolean",
"default": "false"
}
},
"validations": [],
"relations": {
"roles": {
"type": "hasMany",
"model": "Role",
"through": "RoleMapping",
"foreignKey": "principalId"
},
"baggedProducts": {
"type": "hasMany",
"model": "product",
"through": "baggedProduct",
"foreignKey": "customerId"
},
"orders": {
"type": "hasMany",
"model": "order",
"foreignKey": "orderId"
}
},
"acls": [],
"methods": []
}
答案 0 :(得分:0)
根据给定的关系,模型客户有许多模型订单。因此,要访问给定客户的订单,请使用:
customer.order.find({}, function(err, results) {
if(err) throw err;
console.log(results);
});
现在,如果您使用URL来获取结果:您需要找到此方法的网址,如下所示:
{your server}/customer/{id}/orders
否则,如果您使用的是Android SDK,请按照以下步骤操作:Android SDK guide for LoopBack。