-
sequelize includeToday I Learned 2020. 1. 18. 14:02
문제
sequelize를 이용하면 raq query에서 사용하던 join 문을 직접적으로 사용할 수 없다. 그러나, 프로젝트 진행 중에 join 할 부분이 생겨 다른 대안이 있는지 조사해보았다.
해결
sequelize에는 include option을 이용해 join 역할을 수행할 수 있다.
routes/board/comment/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters// 댓글 조회 함수 호출 let result = await models.Comment.findAll({ include: [models.User, models.Board], where: { boardIdx : boardIdx } }); /* ... */ findAll 메소드에 include option을 바꿔 join 을 수행할 수 있었다.
출처
https://velog.io/@cadenzah/sequelize-document-1
Sequelize 공식 Document - (1) Model Usage
모델 사용법 - 이 글은 4. Model Usage를 번역한 글입니다. - 아직 입문자이다보니 오역이 있을 수 있습니다. 양해 부탁드립니다. - 매끄러운 번역을 위하여 의역을 한 경우가 있습니다. 원문의 뜻을 최대한 해치지 않도록 노력했으니 안심하셔도 됩니다. - 영어 단어가 자연스러운 경우 원문 그대로의 영단어를 적었습니다. - 저의 보충 설명은...
velog.io
https://sequelize.org/master/manual/models-usage.html
Manual | Sequelize
sequelize.org
'Today I Learned' 카테고리의 다른 글
form 기본값 주기 (0) 2020.01.21 form에서 put, delete를 지원하지 않는 이유 (0) 2020.01.18 hasMany와 belongsTo 차이점 (0) 2020.01.18 react session 보관 문제 (1) 2020.01.15 CORS cross domain issue (0) 2020.01.15