article.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. author:DataTypes.TEXT,
  38. category:DataTypes.INTEGER,
  39. crop:DataTypes.INTEGER,
  40. seoKeyword:DataTypes.TEXT,
  41. seoDescription:DataTypes.TEXT,
  42. }, {
  43. sequelize,
  44. modelName: 'Article',
  45. });
  46. return Article;
  47. };