我正在尝试查询与确切数量的艺术家相关联的音乐专辑。
我使用多对多表正确关联了模型,但我的查询未能执行我希望它执行的操作。
albumArtists = albumArtists.map((artist) => {
return artist.id;
});
const album = await DB.Album.findOne({
where: {
name: albumName,
},
include: [
{
model: DB.Artist,
through: {
where: {
artistId: {
[Op.and]: albumArtists
}
}
}
},
],
});
我正在尝试查询将
name
设置为 albumName
的专辑,并将 albumArtists
与 artistId
匹配的所有 albumArtists
关联起来。我尝试在
where
对象之外设置我的 through
子句,但这似乎也不起作用。
最佳答案
尝试更新到这个:
through: { model: DB.AlbumArtists // write correct model name }
你也可以简化 where 条件:
where: { artistId: albumArtists }
关于javascript - 按列和关联记录的列序列化查询表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57297551/