node.js - Sequelize query to group and limit base on a forign key -
i'm using sequelize postgresql database. messages data structure looks this:
id message status sernderid receiverid reservationid createdat
i'm trying group messages related reservation , return latest message index them. current query looks this:
message.findall({ where:{$or:[{senderid:user.id}, {receiverid:user.id}]}, group: 'reservationid', order: [['createdat', 'desc' ]], limit: 1 })
the query changes case on reservation id , gives me following error:
message:"column "reservationid" not exist" name:"sequelizedatabaseerror"
first, how prevent query change case , second, there better way write query?
Comments
Post a Comment