article.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // 文章与作物的关联关系
  14. Article.belongsTo(models.Category, {
  15. foreignKey: 'crop',
  16. as: 'cropInfo'
  17. });
  18. }
  19. }
  20. Article.init({
  21. title: {
  22. type:DataTypes.TEXT,
  23. allowNull:false,
  24. validate:{
  25. notNull:{
  26. msg:'标题必须存在'
  27. },
  28. notEmpty:{
  29. msg:'标题不能为空'
  30. },
  31. len:{
  32. args:[1,500],
  33. msg:'标题长度需要在1~500个字符之间'
  34. }
  35. }
  36. },
  37. content: DataTypes.TEXT('long'),
  38. type:DataTypes.INTEGER,
  39. img:DataTypes.TEXT,
  40. date:DataTypes.DATE,
  41. author:DataTypes.TEXT,
  42. category:DataTypes.INTEGER,
  43. crop:DataTypes.INTEGER,
  44. isRecommended:DataTypes.INTEGER,
  45. subtitle:DataTypes.TEXT,
  46. seoKeyword:DataTypes.TEXT,
  47. seoDescription:DataTypes.TEXT,
  48. }, {
  49. sequelize,
  50. modelName: 'Article',
  51. });
  52. return Article;
  53. };