我有这个功能,
module.exports.getDepartments = function () {
return new Promise(function (resolve, reject) {
sequelize.sync().then(function () {
Departments.findAll({
attributes: ['departmentId', 'departmentName']
}).then(function(data){
resolve(data);
}).catch(function(err) {
reject("Error: " + err);
})
});
}
)};
当我console.log()
数据时,我得到所有这些奇怪字段的所有记录!
Departments {
dataValues: { departmentId: 5, departmentName: '' },
_previousDataValues: { departmentId: 5, departmentName: '' },
_changed: {},
_modelOptions:
{ timestamps: true,
validate: {},
freezeTableName: false,
_options:
{ isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [ 'departmentId', 'departmentName' ] },
__eagerlyLoadedAssociations: [],
isNewRecord: false }
Departments {
dataValues: { departmentId: 6, departmentName: 'TEST' },
_previousDataValues: { departmentId: 6, departmentName: 'TEST' },
_changed: {},
_modelOptions:
{ timestamps: true,
validate: {},
freezeTableName: false,
_options:
{ isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [ 'departmentId', 'departmentName' ] },
__eagerlyLoadedAssociations: [],
isNewRecord: false }
我不得不用20个字段来缩短它,但你明白了。这是怎么回事?这使我无法在我的res.render
上运行server.js
,因为它在departmentId
和departmentName
上有所期待,但正在变得越来越多。
答案 0 :(得分:0)
您需要指示Sequelize返回原始数据。默认情况下,它会在行结果上创建实例。
示例:
BoundingBox