user12929912
user12929912

Reputation:

sequelize query where like

The query should return both sample data below since it matches the context data filename and employeeId but my current query only returns the DOC.doc . How do we correct this in sequelize ? using like ?

#Sample context.data.filename
DOC.doc

#Sample Record

DOC.doc
DOC-1.doc

#Code

const file = await context.service.Model.findAll({
    where: {
      employeeId: record.id,
      filename: {
        [Op.like]: `%${context.data.filename}%`,
      },
    },
    paranoid: false,
  });

Upvotes: 1

Views: 1116

Answers (1)

user14191277
user14191277

Reputation:

Considering just the data that you provided, I think the code bellow is gonna work.

const file = await context.service.Model.findAll({
  where: {
    employeeId: record.id,
    filename: {
      [Op.like]: 'DOC%'
    }
  },
  paranoid: false
});

But, for more operations with like, you should see the following table (from this site):

Table from site above

Upvotes: 2

Related Questions