Andrew McFinley Andrew McFinley - 1 year ago 87
Node.js Question

Sequelize js 'include' and 'raw'

I have a relation between two entites like (every chest has one user)


i want to retrieve all chests and their users in one query, so i do

entities.Chest.findAll({include:[{model: entities.User}]})

But i prefer to manipulate them as plain objects, i do

entities.Chest.findAll({raw:true, include:[{model: entities.User}]})

And the result does not include users at all, how can i achieve this?

Answer Source

as you see, raw has some problems with joins (there is issue) try just use instance method #toJSON

entities.Chest.findAll({include:[{model: entities.User}]})
    var chests = chestsSeq.toJSON(); //same as chestsSeq.get({});
    //do something with raw chests object
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download