Unknown column order clause with multi models in include Sequelize

120 views
Skip to first unread message

Romil Lodaya

unread,
Mar 8, 2023, 10:04:09 AM3/8/23
to Sequelize
When I am trying to order by query I am getting an Unknown column 'Recipients.createdAt' in 'the order clause error.
Here is the code:

const recipients = await Recipients.findAll({
order: [["createdAt", "DESC"]],
include: [
{
model: RecipientTagMaps,
attributes: ["id"],
include: [{ model: Tags, attributes: ["id", "name"] }],
},
],
limit: limit,
offset: offset,
where: {
isActive: true,
},
});

// RecipientTagMap Table associate:
RecipientTagMap.associate = function (models) {
// associations can be defined here
RecipientTagMap.belongsTo(models.Tags, { foreignKey: "tagId" });
RecipientTagMap.belongsTo(models.Recipients, { foreignKey: "recipientId" });
};


Reply all
Reply to author
Forward
0 new messages