1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- '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: 'crop',
- as: 'cropInfo'
- });
- }
- }
- 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,
- isRecommended:DataTypes.INTEGER,
- subtitle:DataTypes.TEXT,
- seoKeyword:DataTypes.TEXT,
- seoDescription:DataTypes.TEXT,
- }, {
- sequelize,
- modelName: 'Article',
- });
- return Article;
- };
|