Readlebee/server/sequelize/associations/index.js

17 lines
470 B
JavaScript

const path = require('path');
const fs = require('fs');
module.exports = models => {
const associatedModels = {};
Object.keys(models).forEach(modelName => {
const associationFileName = path.resolve(__dirname, modelName, '.js');
if (fs.existsSync(associationFileName)) {
associatedModels[modelName] = require(associationFileName)(models);
} else {
associatedModels[modelName] = models[modelName];
}
});
return associatedModels;
};