如何使用带有属性的包含与续集? [英] How to use an include with attributes with sequelize?

查看:8
本文介绍了如何使用带有属性的包含与续集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

知道如何在 sequelize 中使用带属性的包含(当您只需要包含包含表的特定字段时)?

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) { ...

推荐答案

这样的东西应该可以工作

Something like this should work

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

这篇关于如何使用带有属性的包含与续集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆