Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ChatRooms
- Participants
- Messages
- Users
- // My current code is:
- User.findAll({
- include: [
- {
- model: Participant,
- include: [
- {
- model: ChatRoom,
- include: [{ model: Message}]
- }
- ],
- order: [[ChatRoom, Message, 'id', 'DESC']]
- }
- ],
- })
- // This is what my server is returning right now,
- // but the ordering is not working:
- // participantId: 2 should be on top as it has a more recent message
- {
- userId: 1,
- name: 'Kevin',
- participants: [
- {
- participantId: 1,
- userId: 1,
- chatRoomId: 1,
- chatRoom:
- {
- chatRoomId: 1,
- Messages: [{
- MessageId: 1,
- message: 'message1',
- userId: 1
- },
- {
- MessageId: 2,
- message: 'message2',
- userId: 2
- }]
- }
- },
- {
- participantId: 2,
- userId: 1,
- chatRoomId: 2,
- chatRoom:
- {
- chatRoomId: 2,
- Messages: [{
- MessageId: 3,
- message: 'message3',
- userId: 1
- },
- {
- MessageId: 4,
- message: 'message4',
- userId: 3
- }]
- }
- }
- ]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement