Another way is to add a default scope to the User model.
Add this in the model's options object
defaultScope: {
attributes: { exclude: ['password'] },
}
Or you can create a separate scope to use it only in certain queries.
Add this in the model's options object
scopes: {
withoutPassword: {
attributes: { exclude: ['password'] },
}
}
Then you can use it in queries
User.scope('withoutPassword').findAll();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…