forked from kaverti/website
29 lines
666 B
JavaScript
29 lines
666 B
JavaScript
module.exports = (sequelize, DataTypes) => {
|
|
let Sequelize = sequelize.Sequelize
|
|
|
|
let PollQuestion = sequelize.define('PollQuestion', {
|
|
question: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
validate: {
|
|
len: {
|
|
args: [1, 256],
|
|
msg: 'The question must be between 1 and 256 characters'
|
|
},
|
|
isString (val) {
|
|
if(typeof val !== 'string') {
|
|
throw new Sequelize.ValidationError('The question must be a string')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
PollQuestion.associate = function (models) {
|
|
PollQuestion.belongsTo(models.User)
|
|
PollQuestion.hasMany(models.PollAnswer)
|
|
PollQuestion.hasMany(models.PollVote)
|
|
}
|
|
|
|
return PollQuestion
|
|
}
|