AlexC
AlexC

Reputation: 95

How to get datavalues in sequelize with `findAll()` and without `raw:true`?

i want to get datavalues when iam using findAll() in sequelize without using raw:true

        Activities.findAll({
         include: [
         {       
           all: true         
          }   
         ],  
       })
        .then(activities => {   
        });

Upvotes: 4

Views: 5369

Answers (2)

Arqam Rafay
Arqam Rafay

Reputation: 135

This is how i solve without using row: true

let rows = await Activities.findAll();
rows = JSON.stringify(rows);
rows = JSON.parse(rows);

rows only get data

Upvotes: 0

Vivek Doshi
Vivek Doshi

Reputation: 58593

Without raw:true , you have to loop through each object and get value out of it that something like this :

Activities.findAll({
    include: [{
        all: true
    }],
}).then(activities => {
    return activities.map( activity => el.get({ plain: true }) );
});

OR

raw : true , produce the . name when include is used , that issue can be solved by nest : true

Activities.findAll({
    raw : true ,
    nest: true , // <--- The issue of raw true, will be solved by this
    include: [{
        all: true
    }],
}).then(activities => {
    console.log(activities);
});

Upvotes: 5

Related Questions