如何在别人模特的地方使用sequelize?

时间:2018-01-17 02:20:06

标签: javascript sequelize.js

const {
    group,
} = req.query
const where = {}

if (group) where['$Group.title$'] = group

models.User
    .findAll({
      where,
      attributes: getAttributes({model: 'User'}),
      include: [{
        model: models.Group,
        attributes: ['title']
      }, {
        model: models.PointHistory
      }]
    })
    .then(result => {
      res.json(result)
    })
    .catch(err => next(err))

这是我的代码。 $Group.title$无效。 我想按组名添加搜索选项。但这是另一种模式。 我该如何解决?

1 个答案:

答案 0 :(得分:0)

试试这个

models.User
    .findAll({
      where,
      attributes: getAttributes({model: 'User'}),
      include: [{
        model: models.Group,
        attributes: ['title'],
        where: {
          title: {
            $like: //yourSeachString
          }
        }
      }, {
        model: models.PointHistory
      }]
    })
    .then(result => {
      res.json(result)
    })
    .catch(err => next(err))