小编Wag*_*rin的帖子

Sequelizejs findAll 排除字段

我知道options.attributes你列出了你想要选择的属性,但有没有办法只排除一个字段?

到目前为止,我已经解决了

User
  .findAll({order: [['id','DESC']]})
  .then(function(users) {
    users = users.filter(function(user){
      delete user.dataValues.password;
      return user;
    });
    return reply( ReplyUtil.ok(users) );
  })
  .catch(function(err){
    return reply( ReplyUtil.badImplementation(err) );
  });
Run Code Online (Sandbox Code Playgroud)

顺便提一句

我不明白为什么你应该使用user.dataValues.password if not delete 不起作用,而不是简单地user.password 如果我像这样调试console.log('pass: ', user.password)我可以看到密码。

node.js sequelize.js

4
推荐指数
3
解决办法
1万
查看次数

标签 统计

node.js ×1

sequelize.js ×1