Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 => {   
        });
like image 752
AlexC Avatar asked Sep 06 '25 10:09

AlexC


1 Answers

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);
});
like image 58
Vivek Doshi Avatar answered Sep 09 '25 05:09

Vivek Doshi