[웹서비스 개발팀] Sequelize

Anna Park·2024년 8월 1일

webservice

목록 보기
29/33

initiate, sequelize

  1. 관계 정의하기(1:1, 1:N, N:M)
    참조 외래키 FK
    users:comments 1:N관계
//user.js
static associate(db) {
    db.User.hasMany(db.Comment, { foreignKey: "commenter", sourceKey: "id" });
//comment.js  
static associate(db) {
  db.Comment.belongsTo(db.User, { foreignKey: "commenter", targetKey: "id" });

1:1

 hasOne/belongsToMany

N:M

belongsToMany/belongsToMany
profile
교육개발, 웹서비스개발, 수학강사

0개의 댓글