使用包含内部属性后,Sequelize 将不会显示数据库字段

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

字段 brnc_name、brn1_name、brn2_name 未显示在 JSON 中。 我真的不知道我的续集代码会发生什么。有谁知道发生了什么事吗? 当我自己在mysql上编写查询时,字段就显示出来了。

async function select_all(params){
    const {brncBrncId, brn1Brn1Id, brn2_id, blnc_status, condition,limit,offset, ousr_id}=params;
   
    const balance = await db.Balance.findAndCountAll({
        include: [{
            attributes:{
                    include:[
                            sequelize.literal(`(
                                SELECT brnc.brnc_name
                                FROM brncs AS brnc
                                WHERE
                                brnc.brnc_id = ocst.brncBrncId
                                ) AS 'brnc_name'`)
                            ,
                            
                            sequelize.literal(`(
                                SELECT brn1.brn1_name
                                FROM brn1s AS brn1
                                WHERE
                                brn1.brn1_id = ocst.brn1Brn1Id
                                LIMIT 1
                                ) AS brn1_name`)
                            ,
                            sequelize.literal(`(
                                SELECT brn2.brn2_name
                                FROM brn2s AS brn2
                                WHERE
                                brn2.brn2_id = ocst.brn2_id
                                LIMIT 1
                                ) AS brn2_name`)
                            ,
                            sequelize.literal(` 
                                CASE blnc_condition 
                                WHEN '1' THEN 'NORMAL' 
                                WHEN '2' THEN 'BERMASALAH' 
                                ELSE 'MACET' 
                                END AS blnc_condition`)
                        ]
            },
            model: db.Customer,
            required: true,
        }],
        where: [brncBrncId ? {brncBrncId : brncBrncId}: {}, brn1Brn1Id ? {brn1Brn1Id : brn1Brn1Id}: {}, brn2_id ? {brn2_id : brn2_id}: {}, {blnc_status : blnc_status} , condition ? condition : {} ],
        limit: limit, 
        offset: offset
    });
    return balance;
}

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

已经找到了,在连接表上设置

raw = true

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