Spaces:
Runtime error
Runtime error
import { | |
Model, | |
DataTypes, | |
InferAttributes, | |
InferCreationAttributes, | |
CreationOptional, | |
} from 'sequelize'; | |
import { sequelize } from './index'; | |
import PwPortfolio from './pwPortfolio'; | |
import { PwUnitInterface } from 'shared/interfaces/pwUnits.interface'; | |
import PwBuilding from './pwBuildings'; | |
class PwUnit | |
extends Model<InferAttributes<PwUnit>, InferCreationAttributes<PwUnit>> | |
implements PwUnitInterface | |
{ | |
declare id?: CreationOptional<number>; | |
declare name: string; | |
declare pw_id: number; | |
declare pw_portfolio_id: number; | |
declare pw_building_id: number; | |
} | |
PwUnit.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', | |
}, | |
}, | |
pw_building_id: { | |
type: DataTypes.INTEGER.UNSIGNED, | |
allowNull: false, | |
references: { | |
model: PwBuilding, | |
key: 'pw_id', | |
}, | |
}, | |
}, | |
{ | |
sequelize, | |
tableName: 'pw_units', | |
underscored: true, | |
freezeTableName: true, | |
timestamps: true, | |
createdAt: 'created_at', | |
updatedAt: 'updated_at', | |
} | |
); | |
PwUnit.belongsTo(PwPortfolio, { foreignKey: 'pw_portfolio_id', targetKey: 'pw_id', as: 'portfolio' }); | |
PwUnit.belongsTo(PwBuilding, { foreignKey: 'pw_building_id', targetKey: 'pw_id', as: 'building' }); | |
export default PwUnit; | |