Spaces:
Runtime error
Runtime error
import { | |
Model, | |
DataTypes, | |
InferAttributes, | |
InferCreationAttributes, | |
CreationOptional, | |
} from 'sequelize'; | |
import { sequelize } from './index'; | |
import PwPortfolio from './pwPortfolio'; | |
import { PwBuildingInterface } from '../shared/interfaces/pwBuilding.interface'; | |
class PwBuilding | |
extends Model<InferAttributes<PwBuilding>, InferCreationAttributes<PwBuilding>> | |
implements PwBuildingInterface | |
{ | |
declare id?: CreationOptional<number>; | |
declare name: string; | |
declare pw_id: number; | |
declare pw_portfolio_id: number; | |
} | |
PwBuilding.init( | |
{ | |
id: { | |
type: DataTypes.INTEGER.UNSIGNED, | |
autoIncrement: true, | |
primaryKey: true, | |
unique: true, | |
}, | |
name: { | |
type: DataTypes.STRING, | |
allowNull: false, | |
}, | |
pw_id: { | |
unique: true, | |
type: DataTypes.INTEGER, | |
allowNull: false, | |
}, | |
pw_portfolio_id: { | |
type: DataTypes.INTEGER.UNSIGNED, | |
allowNull: false, | |
references: { | |
model: PwPortfolio, | |
key: 'pw_id', | |
}, | |
}, | |
}, | |
{ | |
sequelize, | |
tableName: 'pw_buildings', | |
underscored: true, | |
freezeTableName: true, | |
timestamps: true, | |
createdAt: 'created_at', | |
updatedAt: 'updated_at', | |
} | |
) | |
PwBuilding.belongsTo(PwPortfolio, { foreignKey: 'pw_portfolio_id', targetKey: 'pw_id' }); | |
export default PwBuilding | |