Reputation: 721
I try to get records from db.
db.relations.findAll({where: {organisation: orgName}})
.then(found => {
console.log('Found relations by name: ', found[0].dataValues);
})
.catch(error => {
console.log('Error: ', error);
});
And I get only one record but db have more than one records with same name.
Then I try findAll without params
db.relations.findAll()
.then(found => {
console.log('Found relations by name: ', found[0].dataValues);
})
.catch(error => {
console.log('Error: ', error);
});
And I get again one record with id=1
Upvotes: 1
Views: 4935
Reputation: 173
I had a similar issue. I had seeded data with a mismatch of string value for the attribute I was using. Probably not likely your issue but worth a double check.
Defined on migration file
status: {
type: Sequelize.STRING,
defaultValue: 'DRAFT',
values: ['ACTIVE', 'ARCHIVED', 'DRAFT']
}
However, I was looking for 'COMPLETE'.
Upvotes: 0
Reputation: 3622
You are accessing the first value of the array, using found[0]
.
It will be one record.
Also if you need just the data and not the sequelize instance, The you can add a raw property
Something like
Model.findAll({where: {your clause}, raw: true}
Upvotes: 2