model set up and associations

This commit is contained in:
Arjun Patel
2019-01-15 23:14:05 -08:00
parent a4e4394329
commit 86dd4c8cdb
8 changed files with 59 additions and 6 deletions
+19 -1
View File
@@ -1,5 +1,23 @@
module.exports = models => {
const { Donors, Grants } = models;
const { Donors, Grants, Causes, Regions, Organizations } = models;
Donors.hasMany(Grants, { foreignKey: 'donor_id' });
Grants.belongsToMany(Causes, {
through: 'grants_causes',
foreignKey: 'grant_id',
otherKey: 'cause_id'
});
Grants.belongsToMany(Regions, {
through: 'grants_regions',
foreignKey: 'grant_id',
otherKey: 'region_id'
});
Grants.belongsToMany(Organizations, {
through: 'grants_organizations',
foreignKey: 'grant_id',
otherKey: 'organization_id'
});
};