node.js 如何使用带有续集的属性的包含?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21883484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:52:47  来源:igfitidea点击:

How to use an include with attributes with sequelize?

node.jsormsequelize.jsrelationship

提问by borisdiakur

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

知道如何在 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) { ...

回答by Jan Aagaard Meier

Something like this should work

这样的事情应该工作

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