article.js 925 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. const {
  3. Model
  4. } = require('sequelize');
  5. module.exports = (sequelize, DataTypes) => {
  6. class Article extends Model {
  7. /**
  8. * Helper method for defining associations.
  9. * This method is not a part of Sequelize lifecycle.
  10. * The `models/index` file will call this method automatically.
  11. */
  12. static associate(models) {
  13. // define association here
  14. }
  15. }
  16. Article.init({
  17. title: {
  18. type:DataTypes.STRING,
  19. allowNull:false,
  20. validate:{
  21. notNull:{
  22. msg:'标题必须存在'
  23. },
  24. notEmpty:{
  25. msg:'标题不能为空'
  26. },
  27. len:{
  28. args:[1,45],
  29. msg:'标题长度需要子1~45个字符之间'
  30. }
  31. }
  32. },
  33. content: DataTypes.TEXT,
  34. type:DataTypes.INTEGER,
  35. img:DataTypes.TEXT,
  36. date:DataTypes.DATE,
  37. }, {
  38. sequelize,
  39. modelName: 'Article',
  40. });
  41. return Article;
  42. };