articles.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* indent size: 2 */
  2. module.exports = app => {
  3. const DataTypes = app.Sequelize;
  4. const Model = app.model.define('Articles', {
  5. article_id: {
  6. type: DataTypes.INTEGER(10).UNSIGNED,
  7. primaryKey: true,
  8. autoIncrement: true
  9. },
  10. article_title: {
  11. type: DataTypes.STRING(200),
  12. },
  13. article_desc: {
  14. type: DataTypes.STRING(255),
  15. },
  16. article_content: {
  17. type: DataTypes.TEXT,
  18. },
  19. article_image: {
  20. type: DataTypes.STRING(255),
  21. },
  22. article_type: {
  23. type: DataTypes.INTEGER(1).UNSIGNED,
  24. },
  25. category_id: {
  26. type: DataTypes.INTEGER(10).UNSIGNED,
  27. },
  28. article_tags: {
  29. type: DataTypes.STRING(255),
  30. },
  31. article_status: {
  32. type: DataTypes.INTEGER(1).UNSIGNED,
  33. },
  34. article_author: {
  35. type: DataTypes.STRING(100),
  36. },
  37. article_views: {
  38. type: DataTypes.INTEGER(10).UNSIGNED,
  39. },
  40. article_template_info: {
  41. type: DataTypes.STRING(255),
  42. },
  43. article_recommend: {
  44. type: DataTypes.INTEGER(1).UNSIGNED,
  45. },
  46. article_template_list: {
  47. type: DataTypes.STRING(255),
  48. },
  49. article_sort: {
  50. type: DataTypes.INTEGER(10).UNSIGNED,
  51. },
  52. view_auth: {
  53. type: DataTypes.INTEGER(1).UNSIGNED,
  54. },
  55. admin_id: {
  56. type: DataTypes.INTEGER(10).UNSIGNED,
  57. },
  58. update_time: {
  59. type: DataTypes.TIME
  60. },
  61. create_time: {
  62. type: DataTypes.DATE,
  63. }
  64. }, {
  65. tableName: 'szj_articles'
  66. });
  67. Model.associate = function() {
  68. //关联角色表
  69. Model.belongsTo(app.model.AdminUser,{foreignKey:'admin_id',targetKey:'admin_id',as:'admin_user'});
  70. //关联文章分类表
  71. Model.belongsTo(app.model.ArticlesCategory,{foreignKey:'category_id',targetKey:'category_id',as:'category'});
  72. }
  73. //同步:没有就新建,有就不变
  74. Model.sync();
  75. return Model;
  76. };