audiobookshelf/server/models/LibraryFile.js

25 lines
621 B
JavaScript
Raw Permalink Normal View History

2023-03-12 20:51:45 +01:00
const { DataTypes, Model } = require('sequelize')
module.exports = (sequelize) => {
class LibraryFile extends Model { }
LibraryFile.init({
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
}
}, {
sequelize,
2023-03-19 21:19:22 +01:00
modelName: 'libraryFile'
2023-03-12 20:51:45 +01:00
})
2023-03-19 21:19:22 +01:00
const { libraryItem, fileMetadata } = sequelize.models
libraryItem.hasMany(LibraryFile)
LibraryFile.belongsTo(libraryItem)
2023-03-12 20:51:45 +01:00
2023-03-19 21:19:22 +01:00
fileMetadata.hasOne(LibraryFile, { foreignKey: 'fileMetadataId' })
LibraryFile.belongsTo(fileMetadata, { as: 'fileMetadata', foreignKey: 'fileMetadataId' })
2023-03-12 20:51:45 +01:00
return LibraryFile
}