Feathers-Sequelize with Postgres:如何查询数组

Feathers-Sequelize with Postgres: How to query an Array

我想查看一个数组中是否包含一个或多个值。

这是一个模型字段定义:

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

这是我正在测试的查询:

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

这是我收到的错误:

ERROR: TypeError: values.map is not a function

这是对类似问题的引用,我尝试复制解决方案但没有效果。

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

似乎问题出在 Sequelize 版本上。 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)"

所以解决方法是更改​​这行代码

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