codimd/lib/models/author.ts
Raccoon 79a427e616
ts: lib/models/author.js
Signed-off-by: Raccoon <raccoon@hackmd.io>
2021-06-16 18:35:29 +08:00

42 lines
787 B
TypeScript

// external modules
import * as Sequelize from "sequelize";
export = function (sequelize, DataTypes) {
var Author = sequelize.define('Author', {
id: {
type: Sequelize.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
}