Skip to content

Commit

Permalink
feat: model relationship tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeen committed Dec 9, 2021
1 parent 0cd24ce commit db2a92e
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 54 deletions.
7 changes: 1 addition & 6 deletions src/models/co-benefits/co-benefits.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { sequelize } from '../database';
import { Project } from '../projects';

class CoBenefit extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
static associate() {
CoBenefit.belongsTo(Project);
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/models/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
import { Project } from "./projects";
import { CoBenefit } from "./co-benefits";
import { ProjectLocation } from "./locations/index.js";
import { Qualification } from "./qualifications/index.js";
import { Rating } from "./ratings/index.js";
import { RelatedProject } from "./related-projects/index.js";
import { Staging } from "./staging/index.js";
import { Unit } from "./units/index.js";
import { Vintage } from "./vintages/index.js";

Project.associate();
CoBenefit.associate();
ProjectLocation.associate();
Qualification.associate();
Rating.associate();
RelatedProject.associate();
Staging.associate();
Unit.associate();
Vintage.associate();

export * from './projects';
export * from './co-benefits';
export * from './locations';
Expand Down
7 changes: 1 addition & 6 deletions src/models/locations/locations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { sequelize } from '../database';
import { Project } from '../projects';

class ProjectLocation extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
static associate() {
ProjectLocation.belongsTo(Project);
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/models/projects/projects.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import { Rating } from './../ratings';
import { CoBenefit } from './../co-benefits';

class Project extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
static associate() {
Project.hasMany(RelatedProject);
Project.hasMany(Vintage);
Project.hasMany(Qualification);
Expand Down
7 changes: 1 addition & 6 deletions src/models/qualifications/qualifications.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import { Project } from '../projects';
import { Unit } from '../units';

class Qualification extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
static associate() {
Qualification.belongsTo(Project);
Qualification.hasMany(Unit);
}
Expand Down
7 changes: 1 addition & 6 deletions src/models/ratings/ratings.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { sequelize } from '../database';
import { Project } from '../projects/index';

class Rating extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
static associate() {
Rating.belongsTo(Project);
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/models/related-projects/related-projects.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import { sequelize } from '../database';
import { Project } from '../projects';

class RelatedProject extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
static associate() {
RelatedProject.belongsTo(Project);
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/models/staging/staging.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ const { Model } = Sequelize;
import { sequelize } from '../database';

class Staging extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
static associate() {
// define association here
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/models/units/units.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { sequelize } from '../database';
import { Project } from '../projects/index';

class Unit extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
static associate() {
Unit.belongsTo(Project);
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/models/vintages/vintages.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { sequelize } from '../database';
import { Project } from '../projects/index';

class Vintage extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
static associate() {
Vintage.belongsTo(Project);
}
}
Expand Down

0 comments on commit db2a92e

Please sign in to comment.