2020-01-20 23:09:02 +01:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
module.exports = (sequalize, DataTypes) => {
|
2020-01-21 16:28:47 +01:00
|
|
|
const PriceHistory = sequalize.define(
|
|
|
|
|
"PriceHistory",
|
|
|
|
|
{
|
|
|
|
|
id: {
|
|
|
|
|
type: DataTypes.BIGINT,
|
|
|
|
|
autoIncrement: true,
|
|
|
|
|
primaryKey: true,
|
|
|
|
|
allowNull: false
|
|
|
|
|
},
|
|
|
|
|
realEstateId: {
|
|
|
|
|
type: DataTypes.BIGINT,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
unique: "uniquePriceRealEstate",
|
|
|
|
|
references: {
|
|
|
|
|
model: "RealEstates",
|
|
|
|
|
key: "id"
|
|
|
|
|
},
|
|
|
|
|
onUpdate: "CASCADE",
|
|
|
|
|
onDelete: "SET NULL"
|
2020-01-20 23:09:02 +01:00
|
|
|
},
|
2020-01-21 16:28:47 +01:00
|
|
|
price: {
|
|
|
|
|
type: DataTypes.REAL,
|
|
|
|
|
unique: "uniquePriceRealEstate"
|
|
|
|
|
}
|
2020-01-20 23:09:02 +01:00
|
|
|
},
|
2020-01-21 16:28:47 +01:00
|
|
|
{
|
|
|
|
|
freezeTableName: true
|
2020-01-21 01:19:35 +01:00
|
|
|
}
|
2020-01-21 16:28:47 +01:00
|
|
|
);
|
2020-01-20 23:09:02 +01:00
|
|
|
|
|
|
|
|
PriceHistory.associate = models => {
|
|
|
|
|
PriceHistory.hasMany(models.RealEstate, {
|
|
|
|
|
foreignKey: "id",
|
|
|
|
|
sourceKey: "realEstateId",
|
|
|
|
|
targetKey: "id",
|
|
|
|
|
as: "realEstates"
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return PriceHistory;
|
|
|
|
|
};
|