1

亲爱的

我正在尝试为 sequelizejs 选择包含在内的计数,但出现如下错误

Unhandled rejection SequelizeBaseError: ER_BAD_FIELD_ERROR: Unknown column 'User.Orders.id' in 'field list'
    at Query.formatError (/Users/abdulazizaltaleb/Desktop/Ajeer-Dashboard_clone/node_modules/sequelize/lib/dialects/mysql/query.js:175:14)
    at Query._callback (/Users/abdulazizaltaleb/Desktop/Ajeer-Dashboard_clone/node_modules/sequelize/lib/dialects/mysql/query.js:49:21)
    at Query.Sequence.end (/Users/abdulazizaltaleb/Desktop/Ajeer-Dashboard_clone/node_modules/mysql/lib/protocol/sequences/Sequence.js:86:24)
    at Query.ErrorPacket (/Users/abdulazizaltaleb/Desktop/Ajeer-Dashboard_clone/node_modules/mysql/lib/protocol/sequences/Query.js:88:8)
    at Protocol._parsePacket (/Users/abdulazizaltaleb/Desktop/Ajeer-Dashboard_clone/node_modules/mysql/lib/protocol/Protocol.js:280:23)
    at Parser.write (/Users/abdulazizaltaleb/Desktop/Ajeer-Dashboard_clone/node_modules/mysql/lib/protocol/Parser.js:75:12)
    at Protocol.write (/Users/abdulazizaltaleb/Desktop/Ajeer-Dashboard_clone/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/Users/abdulazizaltaleb/Desktop/Ajeer-Dashboard_clone/node_modules/mysql/lib/Connection.js:103:28)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at addChunk (_stream_readable.js:252:12)
    at readableAddChunk (_stream_readable.js:239:11)
    at Socket.Readable.push (_stream_readable.js:197:10)
    at TCP.onread (net.js:589:20)

我所需要的只是从模型返回数据并将这些数据与其他人一起包含以仅获取计数

在我的代码下面,我在代码中使用了一些解释

models.Order.findAll({
    where : {
        userId : {
            $and : {
                $notIn: ['null']
            }
        },
        serviceId : {
            $and : {
                $notIn: ['null']
            }
        }
    },
    limit : 10,
    pageLength : 500,
    order: '`id` DESC',
    include: [
        {
            model : models.User,attributes : ['firstName','lastName','phoneNumber','rankId'],
            include: [
                {
                    model : models.Order
                    // return the count for orders
                }
            ]
        }
    ],
    attributes: ['id','serviceId','orderStatus',
        [sequelize.Sequelize.fn('COUNT', sequelize.Sequelize.col('User.Orders.id')), 'count']
    ],
    group: ['`User.Orders`.`userId`']

所以排队

// return the count for orders

我正在尝试计算模型的数量

model : models.Order

谢谢你

4

0 回答 0