강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của sangmin1242
sangmin1242

câu hỏi đã được viết

[Gia hạn] Tạo NodeBird SNS bằng React

Hỏi đáp trước khi phân phối

models 최신 문법으로 변경 후

Đã giải quyết

Viết

·

282

0

index 페이지에 /Posts 요청에서 

sequelizeeagerloadingerror Image is not associated to Comment

에러가 나고 로그인도 안되요 models 폴더 말고 다른 파일도 수정해야하는 곳이 있나요?

reactnodejsexpressreduxNext.js

Câu trả lời 2

0

tkdals9048님의 프로필 이미지
tkdals9048
Người đặt câu hỏi

이런.. import 를 잘못해오고 있었어요 답변 감사합니다!

0

zerocho님의 프로필 이미지
zerocho
Người chia sẻ kiến thức

Comment랑 Image랑 혹시 연결하셨나요? 두 테이블은 서로 관계가 없습니다. /posts(게시글 불러오는 코드)에서 include 부분도 잘 살펴보세요.


router.get('/', async (req, res, next) => { // GET /posts
try {
const where = {};
if (parseInt(req.query.lastId, 10)) { // 초기 로딩이 아닐 때
where.id = { [Op.lt]: parseInt(req.query.lastId, 10)}
} // 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
const posts = await Post.findAll({
where,
limit: 10,
order: [
['createdAt', 'DESC'],
[Comment, 'createdAt', 'DESC'],
],
include: [{
model: User,
attributes: ['id', 'nickname'],
}, {
model: Image,
}, {
model: Comment,
include: [{
model: User,
attributes: ['id', 'nickname'],
}],
}, {
model: User, // 좋아요 누른 사람
as: 'Likers',
attributes: ['id'],
}, {
model: Post,
as: 'Retweet',
include: [{
model: User,
attributes: ['id', 'nickname'],
}, {
model: Image,
}]
}],
});
res.status(200).json(posts);
} catch (error) {
console.error(error);
next(error);
}
});
Hình ảnh hồ sơ của sangmin1242
sangmin1242

câu hỏi đã được viết

Đặt câu hỏi