2017-03-14 05:02:43 +00:00
|
|
|
'use strict'
|
2016-07-30 03:21:38 +00:00
|
|
|
// external modules
|
2017-03-08 10:45:51 +00:00
|
|
|
var Sequelize = require('sequelize')
|
2016-07-30 03:21:38 +00:00
|
|
|
|
|
|
|
module.exports = function (sequelize, DataTypes) {
|
2017-03-08 10:45:51 +00:00
|
|
|
var Author = sequelize.define('Author', {
|
|
|
|
id: {
|
|
|
|
type: Sequelize.INTEGER,
|
|
|
|
primaryKey: true,
|
|
|
|
autoIncrement: true
|
|
|
|
},
|
|
|
|
color: {
|
|
|
|
type: DataTypes.STRING
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
indexes: [
|
|
|
|
{
|
|
|
|
unique: true,
|
|
|
|
fields: ['noteId', 'userId']
|
|
|
|
}
|
|
|
|
],
|
|
|
|
classMethods: {
|
|
|
|
associate: function (models) {
|
|
|
|
Author.belongsTo(models.Note, {
|
|
|
|
foreignKey: 'noteId',
|
|
|
|
as: 'note',
|
2018-05-25 12:54:00 +00:00
|
|
|
constraints: false,
|
|
|
|
onDelete: 'CASCADE',
|
|
|
|
hooks: true
|
2017-03-08 10:45:51 +00:00
|
|
|
})
|
|
|
|
Author.belongsTo(models.User, {
|
|
|
|
foreignKey: 'userId',
|
|
|
|
as: 'user',
|
2018-05-25 12:54:00 +00:00
|
|
|
constraints: false,
|
|
|
|
onDelete: 'CASCADE',
|
|
|
|
hooks: true
|
2017-03-08 10:45:51 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return Author
|
|
|
|
}
|