我正在尝试通过书架模型从MySQL数据库中获取不同的数据。
部门主管:
Department.distinct('departmentName').fetchAll().then((result) => {
return res.send({
status: '204',
message: 'Data is Fetched',
error: false,
data: result
})
}
部门模型:
Bookshelf.model('Department' , {
tableName:'departments',
hasSecurePassword: true,
hasTimestamps : ['created_at' , 'updated_at'],
softDelete: true,
hidden: ['deleted_at'],
parse: function(response){
if(response.allowUseOfMyContactInformation != null)
response.allowUseOfMyContactInformation = !!+response.allowUseOfMyContactInformation;
return response;
}
})
有人请帮助我出现错误“ Department.distinct不是函数”
问题是您试图对模型而不是部门模型的对象进行查询。
将更改添加到您的部门主管中>
首先,您需要在部门控制器中导入部门模型
const Department = require('your Department model path'); const department = new Department(); department.distinct('departmentName').fetchAll().then((result) => { return res.send({ status: '204', message: 'Data is Fetched', error: false, data: result })
我希望这会对您有所帮助。如果您有任何问题,请告诉我。