获取SQL不同数据书架模型

问题描述 投票:0回答:1

我正在尝试通过书架模型从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不是函数”

node.js bookshelf.js
1个回答
0
投票

问题是您试图对模型而不是部门模型的对象进行查询。

将更改添加到您的部门主管中>

首先,您需要在部门控制器中导入部门模型

       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
        })

我希望这会对您有所帮助。如果您有任何问题,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.