你好,我是Loopback的新手
我在这里使用回送mongodb,目前我有两个集合,即Company和Employee。
在员工集合中,我将公司称为员工表中的外键(在mongo中表示集合)。
Company.json
"properties": {
"_id": {
"type": "number"
},
"name": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {
},
Employee.json
"properties": {
"name": {
"type": "string",
"required": true
},
"age": {
"type": "number",
"required": true
},
"department": {
"type": "string",
"required": true
},
"city": {
"type": "string",
"required": true
},
"salary": {
"type": "number",
"required": true
},
"componyId": {
"type": "objectid",
"required": true
}
},
"validations": [],
"relations": {
"compony": {
"type": "belongsTo",
"model": "Company",
"foreignKey": "componyId"
}
},
请让我在这里遇到错误...
empoyee.js
module.exports = function(Employee) {
console.log('Employee....:', Employee);
Employee.findSalary = function(value, cb) {
console.log('Employee value....:', value, cb);
Employee.find({
where: {
salary: {
gte: value,
},
},
include: {
relation: 'compony',
},
}, cb);
};
Employee.remoteMethod('findSalary', {
accepts: {
arg: 'salary',
type: 'number',
},
returns: {
arg: 'salarys',
type: 'array',
},
http: {
path: '/find-salary',
verb: 'get',
},
});
};
谢谢
答案 0 :(得分:0)
我认为您应该删除此部分:
"componyId": {
"type": "objectid",
"required": true
}
和
include: {
relation: 'compony',
}
可能只是
include: 'compony'
而且我认为您在'comp o ny'中有一个错字,但您始终使用此名称,因此它不应只是问题而已,而不仅仅是问题