Sequelize how to extract specific fields from concatenated tables

I have:

db.Animal.findAll({ attributes: ['id', 'name'], include: [db.Age] }).success(function(results) {
    console.log(JSON.stringify(results));
});

      

It gives me the field ids and NAME from the Animal table ... but I also want to get specific fields from the Age table, not all fields (this works now).

What can I do?

+3


source to share


1 answer


You can specify attributes inside the include array. Try reordering like this:



db.Animal.findAll({ attributes: ['id', 'name'], 
  include: [{ model: db.Age, attributes: ['field1'] }]
})
.success(function(res){ console.log( JSON.stringify(res) ) })

      

+5


source







All Articles