Discussion.findAll({
where : {
discussion_on : profileId,
is_deleted : false ,
is_reply : false
},
limit : 5,
order : [['updated_at','DESC']],
offset:5*(page-1),
// order : [['updated_at','DESC']],
include:[{
model : Profile,
as : 'CommentBy',
attributes:staticData.USER_LAYOUT,
include : [{
model : TeamMember,
as : "TeamSender",
required : false,
attributes : ['receiver', 'title'],
where : sequelize.where(sequelize.col('receiver'),db.sequelize.col('discussion.comment_entity'))
},{
model : TeamMember,
required : false,
as : "TeamReceiver",
attributes : ['sender', 'title'],
where : sequelize.where(sequelize.col('CommentBy.TeamReceiver.sender'),db.sequelize.col('discussion.comment_entity'))
}]
},{
model : Discussion,
as : 'Replies',
required : false ,
order : [['Replies.created_at','ASC']],
where : {
is_deleted : false
} ,
include:[{
model : Profile,
as : "CommentBy",
attributes:staticData.USER_LAYOUT,
include : [{
model : TeamMember,
as : "TeamSender",
required : false,
attributes : ['receiver', 'title'],
where : sequelize.where(sequelize.col('Replies.CommentBy.TeamSender.receiver'),db.sequelize.col('Replies.comment_entity'))
},{
model : TeamMember,
required : false,
as : "TeamReceiver",
attributes : ['sender', 'title'],
where : sequelize.where(sequelize.col('Replies.CommentBy.TeamReceiver.sender'),db.sequelize.col('Replies.comment_entity'))
}]
},{
model:Profile,
as : "CommentEntity",
attributes:staticData.USER_LAYOUT
}]
},{
model:Profile,
as : "CommentEntity",
attributes:staticData.USER_LAYOUT
}]
})
Discussion is the object name. Basically this query fetches all the comments with their replies attached to each comment .I want the replies to be sorted by date as well.
This is what i want to achieve inside Replies . But it does not work
order : [['created_at','ASC']],
Try this, It will helpful for you.
Discussion.findAll({
limit: 5,
....
order: [
['updated_at', 'DESC']
['Replies','created_at', 'ASC'],
],
....
})
You have to define like this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With