使用Postgres的Feathers-Sequelize:如何查询数组

问题描述 投票:1回答:1

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

这是一个模型字段定义:

 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

postgresql sequelize.js feathersjs feathers-sequelize
1个回答
1
投票

似乎问题出在Sequelize版本上。 Feathers.js @daffl的作者之一向我明确了这一点

“在Sequelize v5及更高版本中你需要使用像[Op.contains]这样的符号(http://docs.sequelizejs.com/manual/querying.html#operators)”

所以修复是改变这行代码

where: {
         keywords: {
          [Op.contains]: ['hello'],
         },
       },
© www.soinside.com 2019 - 2024. All rights reserved.