简体   繁体   English

如何在其他人建模的地方使用sequelize?

[英]How can I use sequelize where others model?

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))

This is my code. 这是我的代码。 $Group.title$ is not working. $Group.title$无法正常工作。 I want to add search option by Group name. 我想按组名添加搜索选项。 But this is another model. 但这是另一种模式。 How can I fix it? 我该如何解决?

try this 尝试这个

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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM