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',
|
|
|
|
constraints: false
|
|
|
|
})
|
|
|
|
Author.belongsTo(models.User, {
|
|
|
|
foreignKey: 'userId',
|
|
|
|
as: 'user',
|
|
|
|
constraints: false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return Author
|
|
|
|
}
|