Does Model.count() accept an alias ? #14292
-
does Model.count() accept an alias to return count of the field by that alias instead of word count.
I am passing an array of strings Problemthis is what it returns What I expect
I am using some logic to map through returned array but the problem is Model.count doesn't return 0 count for status for which orders can't be found What I wanteither return count with dynamic provided name (alias) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
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 const ordersCount = await Orders.count({
attributes: ['status'],
where: { status: statuses },
distinct: true,
group: "status",
}); (I don't think distinct is necessary here) |
Beta Was this translation helpful? Give feedback.
It looks like there is a bug. From what I see in the source code,
is supposed to return this:
You can work around it by setting the
attributes
option:(I don't think distinct is necessary here)