Thats my attempt to filter records by custom field:
let pictures = await models.Picture.findAll({
attributes: {
include: [
[sequelize.literal('(SELECT COUNT(*) FROM "pictureLikes" WHERE "pictureLikes"."pictureId"=picture.id)'), 'likesAmount'],
[sequelize.literal('(SELECT COUNT(*) FROM comments WHERE comments."pictureId"=picture.id)'), 'commentsAmount']
]
},
limit,
where: { likesAmount: 2 },
});
But it says that "likesAmount" column doesn't exists, is it possible to solve this problem? Would be grateful for the help.