I have a sequelize model called staff. One of the staff columns is called locations which holds the id’s of all the locations this staff is available at. I want to create a query that uses a Location ID to get all staff active at that location. How can I do that using the ORM?
3
Answers
In Sequelize, you can perform a query to filter staff based on their locations using the include and where options in your query.
const findStaff = await StaffModel.findAll({
where: {
locationId: "your locationId"
}
})
Assuming I have understood your question correctly and your locations column contains CSV data, then you need to use FIND_IN_SET() –
A better option would be to normalize your data as this query is non-SARGable.