Robert Niestroj
Robert Niestroj

Reputation: 16131

Sequelize WHERE AND syntax with functions

i'm using Sequelize 5.18.0 and sequelize-typscript. I need to do a where clause with and and a .fn to find rows where a DateTime column are from a given day.
What is the correct syntax to do this?

  return STTermin.schema(ctx.tenant).findAll({
    where: {
      [Op.or]: [
        {
          [Op.and]: {
            Sequelize.where(Sequelize.fn('DATE', Sequelize.col('von')), '2019-10-17'),
            bis: {
              [Op.is]: null
            }
          }
        },

Which gives me the following error:

enter image description here

Upvotes: 0

Views: 1198

Answers (1)

KenOn10
KenOn10

Reputation: 1968

Both Op.and and Op.or require an array of arguments. So:

 [Op.or] : [
    [Op.and]: [
       Sequelize.where(Sequelize.fn('DATE', Sequelize.col('von')), '2019-10-17'),
       {bis: {[Op.is]: null}}
    ],
    { otherColumn : 123455 }  /* some other condition */
]

FWIW, I find the Operator Aliases to improve code clarity...

Upvotes: 1

Related Questions