如何使用 sequelize 执行此请求?
How to do this request using sequelize?
我想知道使用 sequelize 执行此请求的代码:
select * from "Songs"
where Id in (
select "songId" from "Likes"
where "userId"=1
)
我终于自己找到了怎么做,这是我的代码:
const songs = await models.Songs.findAll({
attributes: ['id', 'title', 'imageUrl', 'nbListening'],
where: {
id: {
[Op.in]: sequelize.literal(
`(select "songId" from "Likes" where "userId"=${req.user.id})`
),
},
},
我想知道使用 sequelize 执行此请求的代码:
select * from "Songs"
where Id in (
select "songId" from "Likes"
where "userId"=1
)
我终于自己找到了怎么做,这是我的代码:
const songs = await models.Songs.findAll({
attributes: ['id', 'title', 'imageUrl', 'nbListening'],
where: {
id: {
[Op.in]: sequelize.literal(
`(select "songId" from "Likes" where "userId"=${req.user.id})`
),
},
},