Sequelize包含使用include时的结果中的引用表行

use*_*255 5 sequelize.js

我有TrackArtist模型定义,关联如下:

db.Track.belongsToMany(db.Artist, {through: 'TracksArtists'});
db.Artist.belongsToMany(db.Track, {through: 'TracksArtists'});
Run Code Online (Sandbox Code Playgroud)

我想搜索曲目并在结果中包含Artist.name:

db.Track
    findAll({ 
        attributes: ['title','year'], 
        where: { title: { like: '%' + string + '%' } },
        include: [{model: db.Artist, attributes: ['name']}]
    })
    .complete(function(err, tracks){ /*...*/});
Run Code Online (Sandbox Code Playgroud)

但是,Sequelize还在结果中包含了来自TracksArtists引用表的一行:

[{"title":"Nightcall","year":2010,"Artists":[{"name":"Kavinsky","TracksArtists":{"createdAt":"2015-01-13T18:41:31.850Z","updatedAt":"2015-01-13T18:41:31.850Z","ArtistId":1,"TrackId":1}}]}]
Run Code Online (Sandbox Code Playgroud)

这是不必要的.如何让它不从TracksArtists返回信息,而不是自己删除它?

Mic*_*sen 11

您可以通过传递空属性数组来关闭连接表属性,如:

include: [{model: db.Artist, attributes: ['name'], through: {attributes: []}}]