poll_answer.js 581 B

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