인프런 커뮤니티 질문&답변
[Error] 여러 개의 태그를 검색하고 싶으면 어떻게 해야 하나요?
작성
·
187
0
const arr = ['테스트', 'test'];
try{
const hash = await Hashtag.findAll({ where : { title : arr }});
console.log(hash);
let post = [];
post = await hash.getItems();
res.render('main', {
title: 'WeAreHere 중고 & 플리마켓 SNS',
posts: posts,
user: req.user,
});
} catch (error) {
console.error(error);
next(error);
}
여러 개의 태그를 검색해보고 싶어서 검색하고 싶은 태그를 arr에 넣고 테스트 해봤습니다. 그러나 아래와 같은 에러만 발생하네요 ㅠㅜ
hash.getItems is not a function
TypeError: hash.getItems is not a function
at D:\Study\Server\nodejs\nodejsLib\URI\routes\search.js:16:27
findAll을 했을 경우에는 어떻게 관계있는 로우를 조회할 수 있을까요?
답변 1
0
제로초(조현영)
지식공유자
hash.forEach로 해서 각각에 대해서 getItems를 할 수도 있는데 그것보다는 그냥 findall할때 include를 사용하는 게 더 효효율적일 것입니다.





