mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-01-13 02:21:39 +00:00
f0b1d85ae9
Signed-off-by: David Mehren <dmehren1@gmail.com>
43 lines
795 B
TypeScript
43 lines
795 B
TypeScript
import {DataTypes} from 'sequelize';
|
|
|
|
|
|
function createAuthorModel(sequelize) {
|
|
const Author = sequelize.define('Author', {
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
primaryKey: true,
|
|
autoIncrement: true
|
|
},
|
|
color: {
|
|
type: DataTypes.STRING
|
|
}
|
|
}, {
|
|
indexes: [
|
|
{
|
|
unique: true,
|
|
fields: ['noteId', 'userId']
|
|
}
|
|
]
|
|
});
|
|
|
|
Author.associate = function (models) {
|
|
Author.belongsTo(models.Note, {
|
|
foreignKey: 'noteId',
|
|
as: 'note',
|
|
constraints: false,
|
|
onDelete: 'CASCADE',
|
|
hooks: true
|
|
});
|
|
Author.belongsTo(models.User, {
|
|
foreignKey: 'userId',
|
|
as: 'user',
|
|
constraints: false,
|
|
onDelete: 'CASCADE',
|
|
hooks: true
|
|
})
|
|
};
|
|
|
|
return Author
|
|
}
|
|
|
|
export = createAuthorModel
|