Update model casing & associations

This commit is contained in:
advplyr 2023-03-19 15:19:22 -05:00
parent 2131a65299
commit 54ca58e610
45 changed files with 830 additions and 561 deletions

View file

@ -13,20 +13,20 @@ module.exports = (sequelize) => {
sequelize,
timestamps: true,
updatedAt: false,
modelName: 'CollectionBook'
modelName: 'collectionBook'
})
// Super Many-to-Many
// ref: https://sequelize.org/docs/v6/advanced-association-concepts/advanced-many-to-many/#the-best-of-both-worlds-the-super-many-to-many-relationship
const { Book, Collection } = sequelize.models
Book.belongsToMany(Collection, { through: CollectionBook })
Collection.belongsToMany(Book, { through: CollectionBook })
const { book, collection } = sequelize.models
book.belongsToMany(collection, { through: CollectionBook })
collection.belongsToMany(book, { through: CollectionBook })
Book.hasMany(CollectionBook)
CollectionBook.belongsTo(Book)
book.hasMany(CollectionBook)
CollectionBook.belongsTo(book)
Collection.hasMany(CollectionBook)
CollectionBook.belongsTo(Collection)
collection.hasMany(CollectionBook)
CollectionBook.belongsTo(collection)
return CollectionBook
}