如何将带有属性的include与sequ​​elize一起使用? [英] How to use an include with attributes with sequelize?

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

问题描述

有什么想法如何在续集中使用带有属性的包含(当您只需要包含被包含表的特定字段时)?

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

推荐答案

类似的方法应该起作用

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

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

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