1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- const { DataTypes } = require('sequelize');
- const connect = require('./connect');
- /*
- type: DataTypes.STRING,
- allowNull: false,
- defaultValue:'',
- comment: '名',
- */
- const model = connect.define(
- __filename.slice(__dirname.length + 1).replace('.js', ''),
- {
- id: {
- type: DataTypes.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- comment: 'id',
- },
- name: {
- type: DataTypes.STRING,
- allowNull: false,
- comment: '地区名',
- },
- cityId: {
- type: DataTypes.INTEGER,
- allowNull: false,
- defaultValue: 0,
- comment: '市id ',
- },
- provinceId: {
- type: DataTypes.INTEGER,
- allowNull: false,
- defaultValue: 0,
- comment: '省id ',
- },
- type: {
- type: DataTypes.INTEGER,
- allowNull: false,
- comment: '1省2市3地区',
- },
- pinyin: {
- type: DataTypes.STRING,
- defaultValue: '',
- comment: '首字母',
- },
- },
- {
- comment: '地区',
- hooks: {
- beforeFind(option) {
- if (!option.order) {
- option.order = [['id', 'ASC']];
- }
- },
- },
- },
- {
- indexes: [
- {
- fields: ['type', 'province_id'],
- },
- {
- fields: ['type', 'city_id'],
- },
- ],
- }
- );
- module.exports = model;
|