• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    해결됨

시퀄라이즈 order에 대해

23.02.23 10:02 작성 조회수 279

1

const post = await Post.findOne({
      where: { id: parseInt(req.query.postId) },
      order: [
        [{ model: Comment }, "createdAt", "ASC"],
        [{ model: Nested_Comment }, "createdAt", "ASC"],
      ],
      include: [
        { model: Image, attributes: ["id", "src"] },
        {
          model: User,
          attributes: ["id", "nickname", "profile_img"],
        },
        {
          model: Comment,
          include: [
            {
              model: User,
              attributes: ["id", "nickname", "profile_img"],
            },
            {
              model: Nested_Comment,
              include: [
                {
                  model: User,
                  attributes: ["id", "nickname", "profile_img"],
                },
              ],
            },
          ],
        },
        {
          model: User,
          as: "Likers",
        },
        { model: Image },
      ],
    });

강좌를 듣고 게시판을 하나 만들고 있는 중인데요

Comment를 createdAt 기준으로 ASC 정렬,

Nested_Comment를 createdAt 기준으로 ASC정렬 하고 싶은데

Comment 까지는 정렬이 되지만 아무리 고쳐봐도 Nested_Comment는 적용이 안되네요.

공식문서도 자세하게 나오지는 않고..

도저히 안되겠어서 질문드립니다. Nested_Comment까지 정렬하고 싶으면

어떻게 order 속성을 작성해야 하나요?

 

 

답변 1

답변을 작성해보세요.

0

https://stackoverflow.com/a/45936923

이런 식으로 Comment와 Nested_Comment를 둘 다 넣으세요.

BBB AAA님의 프로필

BBB AAA

질문자

2023.02.23

감사합니다. 바로 해결됐네요;;