작성
·
210
0
안녕하세요.
아래는 제가 만든 프로젝트 코드 내용과 강의 내용인데요 (Profile = Post 동일한 모델이라고 생각하시면 됩니다.)
저는 데이터를 가져올 때 해당 해시태그만 가져와지는데 뭐가 문제일까요 ..
예를들어 노드를 검색하면 노드를 포함한 포스트(프로필) 전체가 가져와지잖아요
#노드#익스프레스 또는 #노드#리액트 이렇게요.
근데 제가 짠 코드에는 그 포스트(프로필)에 #노드만 따라오네요 ㅠㅠ
const allProfiles = await Profile.findAll({
// where,
// limit : 8,
order: [['createdAt', 'DESC']],
include: [
{
model: Image,
attributes: {
exclude: ['createdAt', 'updatedAt'],
},
},
{
model: Hashtag,
where: { name: decodeURIComponent(req.params.hashtag) },
attributes: {
exclude: ['createdAt', 'updatedAt', 'ProfileTag'],
},
},
],
});
model/hashtag.js
db.Hashtag.belongsToMany(db.Profile, { through: 'ProfileTag' });
model/profile.js
db.Profile.belongsToMany(db.Hashtag, { through: 'ProfileTag' });
답변 1
1
all: true였나, required: true였나 include에 옵션이 있었던 걸로 기억하는데요. 이게 안 된다면
첫 번째 쿼리(위에 보여지는 쿼리)에서는 id만 가져오고, 그 아이디들을 통해서 두 번째 쿼리에서 다시 findAll해서 include해서 다시 만들어내야 합니다.