조인을 했으니 이제 재대로 써봐야지
join 을 안하고 DB를 불러온다고 가정했을때
게시글을 불러오면서 DB 요청
코맨트를 불러오면서 DB 요청..
이러지말고 한번 요청으로 게시글과 그와연관된 코맨트를 불러오자
const post = await posts.findAll(
{ include: [{model :comments, attributes: ['comment']},
{ model : users , attributes: ['userId','email','profile']},
{ model : likes }] },
);
include를 이용하여 해당 DB에 연관되어 있는 DB들을 불러온다..
굿..
댓글을 적고있는데........