mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-02-28 21:19:42 +00:00
Update model casing & associations
This commit is contained in:
parent
2131a65299
commit
54ca58e610
45 changed files with 830 additions and 561 deletions
|
|
@ -11,21 +11,21 @@ module.exports = (sequelize) => {
|
|||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'BookNarrator',
|
||||
modelName: 'bookNarrator',
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
// 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, Person } = sequelize.models
|
||||
Book.belongsToMany(Person, { through: BookNarrator })
|
||||
Person.belongsToMany(Book, { through: BookNarrator })
|
||||
const { book, person } = sequelize.models
|
||||
book.belongsToMany(person, { through: BookNarrator, as: 'narrators', otherKey: 'narratorId' })
|
||||
person.belongsToMany(book, { through: BookNarrator, foreignKey: 'narratorId' })
|
||||
|
||||
Book.hasMany(BookNarrator)
|
||||
BookNarrator.belongsTo(Book)
|
||||
book.hasMany(BookNarrator)
|
||||
BookNarrator.belongsTo(book)
|
||||
|
||||
Person.hasMany(BookNarrator)
|
||||
BookNarrator.belongsTo(Person)
|
||||
person.hasMany(BookNarrator, { foreignKey: 'narratorId' })
|
||||
BookNarrator.belongsTo(person, { as: 'narrator', foreignKey: 'narratorId' })
|
||||
|
||||
return BookNarrator
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue