poll_question.js 679 B

12345678910111213141516171819202122232425262728293031
  1. module.exports = (sequelize, DataTypes) => {
  2. let Sequelize = sequelize.Sequelize
  3. let PollQuestion = sequelize.define('PollQuestion', {
  4. question: {
  5. type: DataTypes.STRING,
  6. allowNull: false,
  7. validate: {
  8. len: {
  9. args: [1, 256],
  10. msg: 'The question must be between 1 and 256 characters'
  11. },
  12. isString (val) {
  13. if(typeof val !== 'string') {
  14. throw new Sequelize.ValidationError('The question must be a string')
  15. }
  16. }
  17. }
  18. }
  19. }, {
  20. classMethods: {
  21. associate (models) {
  22. PollQuestion.belongsTo(models.User)
  23. PollQuestion.hasMany(models.PollAnswer)
  24. PollQuestion.hasMany(models.PollVote)
  25. }
  26. }
  27. })
  28. return PollQuestion
  29. }