Skip to content

Does Model.count() accept an alias ? #14292

Discussion options

You must be logged in to vote

It looks like there is a bug. From what I see in the source code,

const ordersCount = await Orders.count({ 
  where: { status: statuses }, 
  distinct: true, 
  group: "status", 
}); 

is supposed to return this:

[{ status: 'statusA', count: 10 }, { status: 'statusB', count: 20 }]

You can work around it by setting the attributes option:

const ordersCount = await Orders.count({ 
  attributes: ['status'],
  where: { status: statuses }, 
  distinct: true, 
  group: "status", 
}); 

(I don't think distinct is necessary here)

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@uzair004
Comment options

@uzair004
Comment options

@ephys
Comment options

@uzair004
Comment options

Answer selected by uzair004
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants