I have four columns in a movie table and three of these columns should be unique title, description, year.
When I insert a row into this table e.g.
{
title: 'Long Walk',
description: 'Walk to the moon and beyond'
year: 1890
}
I check if any of the three already exists in the table throw error. For that I'm using sequelize OR condition on all three columns
const movie = await this.model.findOne({
where: {
[Op.or]: [
{ title: { [Op.iLike]: title} },
{ description: { [Op.iLike]: description} },
{ year: { [Op.iLike]: year} },
],
},
});
This query tells me if a record already exists if any of the three column matches. Is there a way to know which column matched? I want to know names of the columns that matched.
E.g if after the input given above was inserted into the table, if I give another input
{
title: 'Blue Beach',
description: 'Its a movie about a beach.'
year: 1890
}
This should throw an error as the year 1890 already exists in the table and output me something like 'year column duplicate'.