I have a many to many relationship between User and Category through UserCategory as below.
let user = await User.findAll({
where: {
id: req.query.user
},
attributes: ["id", "name"],
include: [
{
model: models.Category,
as: "interests",
attributes: ["id", "name", "nameTH", "icon"],
through: {
model: models.UserCategory,
as: "user_categories",
attributes: ["id", "userId", "categoryId", "updatedAt"]
}
}
],
// Here, I want to order by updatedAt in user_categories
order: [["user_categories", "updatedAt", "DESC"]]
});
How can I order the result by "updatedAt" inside UserCategory model?