Created
September 13, 2020 15:11
-
-
Save dylansalim3/eca6cc0e6a90f51edd776a5922906a00 to your computer and use it in GitHub Desktop.
Sequelize Basics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//One to One | |
bookDetail.hasOne(category); | |
category.belongsTo(bookDetail); | |
//One to Many | |
borrowBook.belongsTo(user,{foreignKey: 'user_id',}); | |
user.hasMany(borrowBook,{foreignKey: 'user_id',}); | |
//Many to Many | |
bookDetail.belongsToMany(author,{through: "book_author",foreignKey:'book_detail_id'}); | |
author.belongsToMany(bookDetail, {through: "book_author",foreign_key:'author_id'}); | |
//Force rewrite the db with new structure (WILL TRUNCATE ALL DB TABLE AND RECREATE THEM) | |
db.sequelize.sync({force:true}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment