'use strict'; const { Model } = require('sequelize'); module.exports = (sequelize, DataTypes) => { class Article extends Model { /** * Helper method for defining associations. * This method is not a part of Sequelize lifecycle. * The `models/index` file will call this method automatically. */ static associate(models) { // 文章与分类的关联关系 Article.belongsTo(models.Category, { foreignKey: 'category', as: 'categoryInfo' }); } } Article.init({ title: { type:DataTypes.TEXT, allowNull:false, validate:{ notNull:{ msg:'标题必须存在' }, notEmpty:{ msg:'标题不能为空' }, len:{ args:[1,500], msg:'标题长度需要在1~500个字符之间' } } }, content: DataTypes.TEXT('long'), type:DataTypes.INTEGER, img:DataTypes.TEXT, date:DataTypes.DATE, author:DataTypes.TEXT, category:DataTypes.INTEGER, crop:DataTypes.INTEGER, seoKeyword:DataTypes.TEXT, seoDescription:DataTypes.TEXT, }, { sequelize, modelName: 'Article', }); return Article; };