Skip to content

Commit

Permalink
chore: 🔧 implements associations
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasvmx committed Mar 8, 2022
1 parent a5a4024 commit 45e3ccb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/database/migrations/20220308002240-feeding-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/model/FeedingHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class FeedingHistory extends Model {
}
);
}

static associate(models) {
this.belongsTo(models.Pixel, { foreignKey: "pixel_id" });
}
}

module.exports = { FeedingHistory };
1 change: 1 addition & 0 deletions src/model/Pixel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
}
}
Expand Down

0 comments on commit 45e3ccb

Please sign in to comment.