Skip to content

$any operator is not working with $like #4313

Closed

Description

@lbeschastny

According to sequelize documentation, $any operator could be combined with $like to produce LIKE ANY PostgreSQL query:

$like: { $any: ['cat', 'hat']}

But it's not working in latest [email protected].

Consider the following code example:

var Sequelize = require('sequelize');

var sequelize = new Sequelize('test', 'username', 'password', {
  dialect: 'postgres',
  logging: false
});

var Test = sequelize.define('Test', {
  id: {
    type: Sequelize.INTEGER,
    primaryKey: true
  },
  str: Sequelize.STRING
});

sequelize.sync().then(function () {
  return Test.findAll({
    where: {
      str: {
        $like: {
          $any: ['foo%', 'bar%']
        }
      }
    }
  });
}).then(function (data) {
  console.log('Success');
}, function (err) {
  console.error(err);
});

Though this query looks valid, it throws the following error:

{ [SequelizeValidationError: ["foo%","bar%"] is not a valid string]
  name: 'SequelizeValidationError',
  message: '["foo%","bar%"] is not a valid string',
  errors: [] }

It looks like sequelize attempts to validate ['foo%', 'bar%'] array against foo data type, which is wrong.

Activity

  1. janmeier commented on Aug 13, 2015

    @janmeier
    Member

    Merged into #4314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions