For example if the array surveyIdsArr is passed in with the following items in it.
surveyIdsArr = [
'ac9d491d-9998-4866-956d-9d3107aa341d',
'f71cfa71-ad1a-40dc-ad19-7f799fef0a31',
'a9606715-c865-4f99-9afc-48b79af77caa',
'f22c221d-2052-45af-a1ba-9774ac524a1c',
'33c47cdb-8a66-45a8-a8ff-cc60de6ce9fc'
]
Then how to fetch the data in the same order as the elements in the array
Right now i am getting elements 33c47cdb-8a66-45a8-a8ff-cc60de6ce9fc , 22c221d-2052-45af-a1ba-9774ac524a1c, f71cfa71-ad1a-40dc-ad19-7f799fef0a31 and like this
I am using sequelize as the ORM
Following is the code to fetch the data
let fetchedSurveys = await Survey.findAndCountAll({
where: {
id: {
[Op.in]: surveyIdsArr,
},
},
include: [
{
model: User,
as: "owner",
},
{
model: Tag,
as: "tags",
attributes: ["id", "tagName"],
},
],
// helpful in lazy fetching
offset: offset,
limit: limit,
distinct: true,
col: "id",
});