audiobookshelf/server/models/Person.js

26 lines
692 B
JavaScript
Raw Normal View History

2023-03-12 20:51:45 +01:00
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
2023-03-18 22:56:57 +01:00
FileMetadata.hasMany(Person, { foreignKey: 'ImageFileId' })
Person.belongsTo(FileMetadata, { as: 'ImageFile', foreignKey: 'ImageFileId' }) // Ref: https://sequelize.org/docs/v6/core-concepts/assocs/#defining-an-alias
2023-03-12 20:51:45 +01:00
return Person
}