인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

heedo's profile image
heedo

asked

[Renewal] Creating NodeBird SNS with React

Setting up a sequel relationship

user,post - comment 관계질문

Written on

·

346

0

제로초님 nodebird에서

comment 관계에서는

user.hasmany(comment)

post.hasmany(comment)  이렇게 관계를 설정하였는데

이는 아무 유저가 comment 작성이 가능하게 하기위해 이렇게 하였고 

 

상품구매 리뷰에서는 상품을 구매한 사람에 한해서만 comment를 작성해야만 하니

comment는 user, product의 belongsToMany로

관계 설정을 해줘야 한다고 판단했는데 

 맞을까요?

 

expressreactreduxnodejsNext.js

Answer 1

1

zerocho님의 프로필 이미지
zerocho
Instructor

아뇨. 상품 구매더라도 User.hasMany(comment)가 맞습니다. comment.belongsTo(User)이고요.

아무 유저가 리뷰를 작성하느냐 마느냐는 디비단에서 검증하는 게 아니라 비즈니스 로직에서 검증하는 겁니다.

heedo님의 프로필 이미지
heedo
Questioner

아 ! 감사합니다

heedo's profile image
heedo

asked

Ask a question