eGlu
eGlu

Reputation: 807

Feathers-Sequelize with Postgres: How to query an Array

I want to see if an array contains one or more values inside it.

This is a model field definition:

 keywords: {
              type: Sequelize.ARRAY(Sequelize.STRING),
              defaultValue: [],
              allowNull: false,
           },

This is the query I am testing:

context.app.services.jobOffers.Model.findAll({
        where: {
            keywords: {
                $contains: ['hello'],
            },
        },
    })
     .then(result => {
         console.log('RESULT:', result)
     })
     .catch(err => {
            console.log('ERROR:', err)
     })

This is the error I am receiving:

ERROR: TypeError: values.map is not a function

This is a reference to a similar issue, where I tried to replicate the solution but to no effect.

https://github.com/feathersjs-ecosystem/feathers-sequelize/issues/135

Upvotes: 1

Views: 1389

Answers (1)

eGlu
eGlu

Reputation: 807

It seems the issue was with the Sequelize versions. This was made clear to me by one of the authors of Feathers.js @daffl

"In Sequelize v5 and later you need to use Symbols like [Op.contains] see (http://docs.sequelizejs.com/manual/querying.html#operators)"

So the fix is to change this line of code

where: {
         keywords: {
          [Op.contains]: ['hello'],
         },
       },

Upvotes: 1

Related Questions