Reputation: 19
I would like to know the code to write to execute this request using sequelize:
select * from "Songs"
where Id in (
select "songId" from "Likes"
where "userId"=1
)
Upvotes: 0
Views: 71
Reputation: 19
I finaly found by myself how to do it, here is my code :
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})`
),
},
},
Upvotes: 1