import {Model, DataTypes} from 'sequelize'; import {sequelize} from './Connection'; interface CategoriesInterface extends Model { id: number; name: string; slug: string; parent_id: number; } const CategoriesModel = sequelize.define('Categories', { id: { type: DataTypes.INTEGER.UNSIGNED, autoIncrement: true, primaryKey: true, }, name: { type: new DataTypes.STRING(400), allowNull: false, }, slug: { type: DataTypes.STRING(100), allowNull: false, }, parent_id: { type: DataTypes.INTEGER.UNSIGNED, allowNull: true, references: {model: 'Categories', key: 'id'}, onDelete: 'CASCADE', } }, { tableName: 'tb_categories', freezeTableName: true, timestamps: true, underscored: true, name: { singular: 'Category', plural: 'Category' }, } ); export {CategoriesModel, CategoriesInterface};