Relative Content

Tag Archive for nestjssequelize.jssequelize-typescript

Reference main column from subquery Sequelize

const customers = await this.repository.findAndCountAll({ where: condition, attributes: { // exclude: [‘user_id’, ‘account_id’, ‘deletedAt’], include: [ [ Sequelize.literal(`( SELECT SUM(amount) FROM transactions WHERE transactions.customer_id = customers.id and transaction_type=’PAYOUT’ )`), ‘totalDebit’ ] ] }, limit, offset, include: { association: ‘groups’, where: { id: groupId }, through: { attributes: [] }, attributes:[], required: true }, order:[[‘createdAt’, ‘DESC’]], […]