Skip to content

Commit

Permalink
feat: add vintage_unit junction
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael.Taylor committed Dec 15, 2021
1 parent c1b119e commit 4dc71a6
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 13 deletions.
14 changes: 14 additions & 0 deletions migrations/20211215231227-vintage-unit-junction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('vintage_unit', {
unitId: Sequelize.INTEGER,
vintageId: Sequelize.INTEGER,
});
},

down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('vintage_unit');
},
};
3 changes: 0 additions & 3 deletions src/models/co-benefits/co-benefits.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ class CoBenefit extends Model {
static associate() {
CoBenefit.belongsTo(Project, {
onDelete: 'CASCADE',
foreignKey: {
allowNull: false,
},
});
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/models/locations/locations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ class ProjectLocation extends Model {
static associate() {
ProjectLocation.belongsTo(Project, {
onDelete: 'CASCADE',
foreignKey: {
allowNull: false,
},
});
}
}
Expand Down
1 change: 1 addition & 0 deletions src/models/qualifications/qualifications.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Qualification extends Model {
// https://gist.github.com/elliette/20ddc4e827efd9d62bc98752e7a62610#some-important-addendums
Qualification.belongsToMany(Unit, {
through: 'qualification_unit',
as: 'qualification',
});
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/models/ratings/ratings.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ class Rating extends Model {
static associate() {
Rating.belongsTo(Project, {
onDelete: 'CASCADE',
foreignKey: {
allowNull: false,
},
});
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/models/related-projects/related-projects.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ class RelatedProject extends Model {
static associate() {
RelatedProject.belongsTo(Project, {
onDelete: 'CASCADE',
foreignKey: {
allowNull: false,
},
});
}
}
Expand Down
1 change: 1 addition & 0 deletions src/models/units/units.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Unit extends Model {
// https://gist.github.com/elliette/20ddc4e827efd9d62bc98752e7a62610#some-important-addendums
Unit.belongsToMany(Unit, {
through: 'qualification_unit',
as: 'unit',
});
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/models/vintages/vintages.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import ModelTypes from './vintages.modeltypes.cjs';
class Vintage extends Model {
static associate() {
Vintage.belongsTo(Project);
Vintage.belongsToMany(Unit);
Vintage.belongsToMany(Unit, {
through: 'vintage_unit',
as: 'vintage',
});
}
}

Expand Down

0 comments on commit 4dc71a6

Please sign in to comment.