Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. ChatRooms
  2. Participants
  3. Messages
  4. Users
  5.  
  6. // My current code is:
  7.  
  8. User.findAll({
  9. include: [
  10. {
  11. model: Participant,
  12. include: [
  13. {
  14. model: ChatRoom,
  15. include: [{ model: Message}]
  16. }
  17. ],
  18. order: [[ChatRoom, Message, 'id', 'DESC']]
  19. }
  20. ],
  21. })
  22.  
  23. // This is what my server is returning right now,
  24. // but the ordering is not working:
  25. // participantId: 2 should be on top as it has a more recent message
  26. {
  27. userId: 1,
  28. name: 'Kevin',
  29. participants: [
  30. {
  31. participantId: 1,
  32. userId: 1,
  33. chatRoomId: 1,
  34. chatRoom:
  35. {
  36. chatRoomId: 1,
  37. Messages: [{
  38. MessageId: 1,
  39. message: 'message1',
  40. userId: 1
  41. },
  42. {
  43. MessageId: 2,
  44. message: 'message2',
  45. userId: 2
  46. }]
  47. }
  48. },
  49. {
  50. participantId: 2,
  51. userId: 1,
  52. chatRoomId: 2,
  53. chatRoom:
  54. {
  55. chatRoomId: 2,
  56. Messages: [{
  57. MessageId: 3,
  58. message: 'message3',
  59. userId: 1
  60. },
  61. {
  62. MessageId: 4,
  63. message: 'message4',
  64. userId: 3
  65. }]
  66. }
  67. }
  68. ]
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement