Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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) { ...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
453 views
Welcome To Ask or Share your Answers For Others

1 Answer

Something like this should work

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...