Sequelize.js sequelize findAll()只返回一条记录
我试图从数据库中获取记录Sequelize.js sequelize findAll()只返回一条记录,sequelize.js,Sequelize.js,我试图从数据库中获取记录 db.relations.findAll({where: {organisation: orgName}}) .then(found => { console.log('Found relations by name: ', found[0].dataValues); }) .catch(error => { console.log('Error: ', erro
db.relations.findAll({where: {organisation: orgName}})
.then(found => {
console.log('Found relations by name: ', found[0].dataValues);
})
.catch(error => {
console.log('Error: ', error);
});
我只得到一条记录,但db有多条同名记录
然后我尝试不带参数的findAll
db.relations.findAll()
.then(found => {
console.log('Found relations by name: ', found[0].dataValues);
})
.catch(error => {
console.log('Error: ', error);
});
我再次得到一条id=1的记录,您正在使用
found[0]
访问数组的第一个值。
这将是一个记录
另外,如果您只需要数据,而不需要sequelize实例,
您可以添加原始属性
差不多
Model.findAll({where: {your clause}, raw: true}
我也有类似的问题。我为正在使用的属性添加了字符串值不匹配的种子数据。可能不太可能是您的问题,但值得仔细检查 在迁移文件上定义
status: {
type: Sequelize.STRING,
defaultValue: 'DRAFT',
values: ['ACTIVE', 'ARCHIVED', 'DRAFT']
}
然而,我在寻找“完整的”