audiobookshelf/server/models/Person.js
2023-03-19 15:19:22 -05:00

26 lines
692 B
JavaScript

const { DataTypes, Model } = require('sequelize')
module.exports = (sequelize) => {
class Person extends Model { }
Person.init({
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
type: DataTypes.STRING,
name: DataTypes.STRING,
asin: DataTypes.STRING,
description: DataTypes.TEXT
}, {
sequelize,
modelName: 'person'
})
const { fileMetadata } = sequelize.models
fileMetadata.hasMany(Person, { foreignKey: 'imageFileId' })
Person.belongsTo(fileMetadata, { as: 'imageFile', foreignKey: 'imageFileId' }) // Ref: https://sequelize.org/docs/v6/core-concepts/assocs/#defining-an-alias
return Person
}