I have a BagEntity and ItemsEntity (simplified). It is my intention to fetch a particular bag with all items associated. This part is working so far.
The problem is that the order of items is determined by its order column, but, for some reason, the result is not being sorted.
Please note that I have double checked the actual value of order of each record. The values are correct. Further, I have checked the generated SQL-statment which does not contain the ORDER BY directive.
return await BagEntity.findAll({
include: [
{
model: ItemsEntity,
order: [[ItemsEntity, 'order', 'ASC']],
// order: [['order', 'ASC']],
}
],
where: { id: bagId },
});
I've tried various options from here but none of them worked.
Expected result
{
"name": "My bag",
"items": [
{ order: 0, name: "Some item" },
{ order: 1, name: "Another item" },
{ order: 2, name: "Yet another item" }
]
}
Actual result
{
"name": "My bag",
"items": [
{ order: 0, name: "Some item" },
{ order: 2, name: "Yet another item" },
{ order: 1, name: "Another item" }
]
}