Sequelize

raccoonback·2019년 10월 15일
0

nodejs

목록 보기
1/1
post-thumbnail

Sequelize

Association

  • source.BelongsTo(target): source가 연관관계의 주인이 되어 Target을 참조한다. => target model name와 pk 이름을 합친 것을 외래키 네이밍이 이루어진다.

  • source.HasOne(target): target이 연관관계의 주인이 되고, 해당 Model 이름을 통해 get/set 메서드가 source.prototype 객체에 생성된다.

  • source.HasMany(target): target이 연관관계의 주인이 되고, 해당 Model 이름을 통해 get/set 메서드가 source.prototype 객체에 생성된다.

  • source.BelongsToMany(target, {through: 'Mediate'}): N : M 관계에서 Mediate 모델을 생성하고 Mediate 모델이 관계의 주인이 된다. through은 필수적이다. get/set/add Targets, addTarget 메서드가 source.prototype 객체에 생성되고, get/set/add Sources, addSource 메서드가 targe.prototype 객체에 생성된다.

1 : 1 상황에 따라서 BelongsTo, HasOne 을 사용해야할 상황이 다르다.

versioning 과 isolation 차이

profile
한번도 실수하지 않은 사람은, 한번도 새로운 것을 시도하지 않은 사람이다.

0개의 댓글