2020-01-14 23:26:39 +01:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
module.exports = models => {
|
|
|
|
const associatedModels = {};
|
|
|
|
|
|
|
|
Object.keys(models).forEach(modelName => {
|
2020-01-25 21:52:37 +01:00
|
|
|
const associationFileName = path.resolve(__dirname, modelName + '.js');
|
2020-01-14 23:26:39 +01:00
|
|
|
if (fs.existsSync(associationFileName)) {
|
|
|
|
associatedModels[modelName] = require(associationFileName)(models);
|
|
|
|
} else {
|
|
|
|
associatedModels[modelName] = models[modelName];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return associatedModels;
|
|
|
|
};
|