.../routers/posts.js:65
allPosts.sort(sortDateDescending);
TypeError: allPosts.sort is not a function
이유가 뭐지?? allPosts가 array가 아닌가?? -> console 로 출력 해보자
<시도>
const allPosts = Post.findAll();
console.log(allPosts);
console.log(Array.isArray(allPosts);
<결과>
// console.log(allPosts)의 출력 결과
Promise {
<pending>,
[Symbol(async_id_symbol)]: 1230,
[Symbol(trigger_async_id_symbol)]: 1222
}
// console.log(Array.isArray(allPosts))의 출력 결과
false
TypeError: allPosts.sort is not a function
>> 첫번째 출력은 뭔지 모르겠으나, Array 형식이 아니라고 하여 형식을 변환 후 출력
const allPosts = Post.findAll();
const allPostsArray = Array.from(allPosts)
console.log(allPostsArray); // 출력 : []
console.log(Array.isArray(allPostsArray));// 출력: true
<< 코드는 정상적으로 작동하는데 받아오는 값이 없다>>
- Sequelize 에서 findAll 조사 : https://sequelize.org/api/v6/class/src/model.js~model#static-method-findAll.
..... 문제는 단순했다... await 를 쓰지 않은 상태에서 array 형태로 변형 시켜서 allPosts 에 아무런 값이 담기지 않았다.
//const allPosts = Post.findAll();
const allPosts = await Post.findAll();
'미니프로젝트 > 지하철역 보관함대여 앱' 카테고리의 다른 글
[미니 프로젝트] [1] [issue 8] 페이지네이션 (1) | 2023.12.27 |
---|---|
[미니 프로젝트] [1][issue 1] jwt token 이용하여 유저의 로그인 여부 확인 (0) | 2023.12.25 |
[미니프로젝트] [1] 구현할 기능 목록 (0) | 2023.12.25 |
미니프로젝트 [문제점] : post 와 해당 comment 지우기 (0) | 2023.10.17 |
미니프로젝트 [Error]: post를 추가, 관계의 중요성 (0) | 2023.10.13 |