diff --git a/src/database/migrations/20220308002240-feeding-history.js b/src/database/migrations/20220308002240-feeding-history.js index 9bb4b60..408ca8e 100644 --- a/src/database/migrations/20220308002240-feeding-history.js +++ b/src/database/migrations/20220308002240-feeding-history.js @@ -15,6 +15,13 @@ module.exports = { type: Sequelize.DATE, allowNull: false, }, + pixel_id: { + type: Sequelize.INTEGER, + allowNull: true, + references: { model: "pixels", key: "id" }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }, created_at: { type: Sequelize.DATE, allowNull: false, diff --git a/src/model/FeedingHistory.js b/src/model/FeedingHistory.js index c13e7f8..c45eda3 100644 --- a/src/model/FeedingHistory.js +++ b/src/model/FeedingHistory.js @@ -14,6 +14,10 @@ class FeedingHistory extends Model { } ); } + + static associate(models) { + this.belongsTo(models.Pixel, { foreignKey: "pixel_id" }); + } } module.exports = { FeedingHistory }; diff --git a/src/model/Pixel.js b/src/model/Pixel.js index 0824291..7297e99 100644 --- a/src/model/Pixel.js +++ b/src/model/Pixel.js @@ -18,6 +18,7 @@ class Pixel extends Model { static associate(models) { this.belongsTo(models.Team, { foreignKey: "team_id" }); this.hasMany(models.Feature, { foreignKey: "pixel_id" }); + this.hasMany(models.FeedingHistory, { foreignKey: "pixel_id" }); this.belongsTo(models.User, { foreignKey: "user_id" }); } }