Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

sequelize count multiple associations

attributes: {
  include: [
    // count paid using case/sum via `status` != 'UNPAID'
    [ sequelize.fn('sum', sequelize.literal("CASE WHEN (`Invoices`.`status` != 'UNPAID' THEN 1 ELSE 0 END")), 'paid_count' ],
    // count unpaid using case/sum via `status` = 'UNPAID'
    [ sequelize.fn('sum', sequelize.literal("CASE WHEN (`Invoices`.`status` = 'UNPAID' THEN 1 ELSE 0 END")), 'unpaid_count' ],
  ],
  // ...
},
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sequelize #count #multiple #associations
ADD COMMENT
Topic
Name
4+6 =