import { Sequelize, DataTypes } from 'sequelize' import { Application } from '../declarations' export default (app: Application): any => { const sequelizeClient: Sequelize = app.get('sequelizeClient') const componentType = sequelizeClient.define('component_type', { type: { type: DataTypes.STRING, allowNull: false, primaryKey: true, unique: true } }, { hooks: { beforeCount (options: any) { options.raw = true }, beforeUpdate (instance: any, options: any) { throw new Error("Can't update a type!") } }, timestamps: false }); (componentType as any).assocate = (models: any) => { (componentType as any).hasMany(models.component, { foreignKey: 'componentType' }) } return componentType }