Thank you @Nicolas.M
Answers:
Does this issue happen on all your collections ?
Yes
Do you have anything particular about your SQL schema that could cause this ?
No
Do you encounter issues with the list query as well ?
No
list and count should be very similar queries.
I understand, but in the count (in your code) you call the getOrder
which is not involved in list (where you call getOrderFromSort
).
This is a slight but important difference
This is your code for the list operation:
And this is your code form the count operation:
In order to help us reproduce and investigate this issue, could you please share the query that is generated by sequelize / SQL to perform the count (in private message if you prefer)?
This is the query (sequelize) you are generating. We got it by inserting a console.log here in your code, to see the query
you’re generating:
NB: the above code comes from this file (on your side): forestadmin/datasource-sequelize/dist/collection.js
{
"attributes": [
[
{
"fn": "COUNT",
"args": [
{
"col": "*"
}
]
},
"__aggregate__"
]
],
"where": {},
"include": [],
"order": [
[
{
"col": "__aggregate__"
},
"DESC NULLS LAST"
]
],
"subQuery": false,
"raw": true
}
As you can see the "col": "__aggregate__"
is obviously wrong !
In the sequelize lib thay state that col
can be used only for DB-existing columns (not aliases). But youre using col on an alias.
@Nicolas.M
as I told in my first message in you file @forestadmin/datasource-sequelize/src/utils/aggregation.ts
you already noticed that you have something wrong about the count. Here you have a “FIXME” comment!!!
And we tried to fix this for you, showing you the patch we’re suggesting (see my first message).
Please check our patch and fix this consistently with your lib
Thank you in advance
Matteo