How to use an include with attributes with sequelize?

borisdiakur picture borisdiakur · Feb 19, 2014 · Viewed 61.2k times · Source

Any idea how to use an include with attributes (when you need to include only specific fields of the included table) with sequelize?

Currently I have this (but it doesn't work as expected):

var attributes = ['id', 'name', 'bar.version', ['bar.last_modified', 'changed']];
foo.findAll({
    where      : where,
    attributes : attributes,
    include    : [bar]
}).success(function (result) { ...

Answer

Jan Aagaard Meier picture Jan Aagaard Meier · Feb 20, 2014

Something like this should work

foo.findAll({
    where      : where,
    attributes : attributes,
    include    : [{ model: bar, attributes: attributes}]
}).success(function (result) {