codestates / codestates/BookDam
22.01.01 Dev-Log
- Dominant language
- JavaScript
- Stars
- 1
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
### 오늘은 어떻게 프로젝트에 기여했나요?
- 데이터 베이스 테이블을 생성하고 테이블간 연관관계를 설정해주었습니다.
### 오늘의 프로젝트에서 힘든 점은 무엇인가요?
아래와 같이 테이블간 연관관계를 설정하기 위해 학습하고 반영을 했지만, 아직 더미데이터와 controller를 만들지 않아
확인하지 못하는 점에서 아쉬웠습니다.
```js
//User 테이블 연관관계
static associate (models) {
// define association here
User.hasMany(models.follow, {foreignKey: 'id', sourceKey: 'user_Id'});
User.hasMany(models.post, {foreignKey: 'id', sourceKey: 'user_Id'});
}
```
```js
//Follow 테이블 연관관계
static associate (models) {
Follow.belongsTo(models.User, {foreignKey: 'id', targetKey: 'user_Id'});
// define association here
}
--------------------------------------------------------------------------------------------------
await queryInterface.addConstraint("Follows", {
fields: ["user_Id"],
type: "foreign key",
name: "fk_Follow_User",
references: {
table: "Users",
field: "id",
},
onDelete: "cascade",
onUpdate: "cascade",
})
```
```js
//Post 테이블 연관관계
static associate (models) {
Post.belongsTo(models.User, {foreignKey: 'id', targetKey: 'user_Id'});
// define association here
}
--------------------------------------------------------------------------------------------------
await queryInterface.addConstraint("Posts", {
fields: ["user_Id"],
type: "foreign key",
name: "fk_Post_User",
references: {
table: "Users",
field: "id",
},
onDelete: "cascade",
onUpdate: "cascade",
})
```
### 다음 주에는 프로젝트에 기여하기 위해 무엇을 해야 하나요?

- [ ] 더미데이터와 controller를 만들어서 include가 잘 작동 되는 지 확인.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.