roles.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* indent size: 2 */
  2. module.exports = app => {
  3. const DataTypes = app.Sequelize;
  4. const Model = app.model.define('Roles', {
  5. role_id: {
  6. type: DataTypes.INTEGER(10).UNSIGNED,
  7. primaryKey: true,
  8. autoIncrement: true
  9. },
  10. role_desc: {
  11. type: DataTypes.STRING(255),
  12. },
  13. role_name: {
  14. type: DataTypes.STRING(20),
  15. },
  16. admin_id: {
  17. type: DataTypes.INTEGER(10).UNSIGNED,
  18. },
  19. update_time: {
  20. type: DataTypes.TIME
  21. },
  22. create_time: {
  23. type: DataTypes.DATE,
  24. }
  25. }, {
  26. tableName: 'szj_roles'
  27. });
  28. Model.associate = function() {
  29. //关联管理员表
  30. Model.belongsTo(app.model.AdminUser,{foreignKey:'role_id',targetKey:'role_id',as:'admin_user'});
  31. //关联管理员表
  32. Model.belongsTo(app.model.AdminUser,{foreignKey:'admin_id',targetKey:'admin_id',as:'admin_user1'});
  33. }
  34. //同步:没有就新建,有就不变
  35. Model.sync();
  36. return Model;
  37. };