diff --git a/packages/db/src/db.js b/packages/db/src/db.js index da24a1e..1af3311 100644 --- a/packages/db/src/db.js +++ b/packages/db/src/db.js @@ -39,8 +39,9 @@ export async function createDatabaseConnection(latus) { // eslint-disable-next-line no-console const Models = latus.invokeReduce('@latus/db/models'); debug('models: %O', Object.keys(Models)); - /* eslint-disable no-param-reassign */ - Object.entries(Models) + const map = latus.invokeComposed('@latus/db/models.decorate', Models); + debug('composed: %O', Object.keys(map)); + Object.entries(map) .filter(([, Model]) => Model.attributes) .forEach(([, Model]) => { Model.init(Model.attributes, { @@ -48,10 +49,9 @@ export async function createDatabaseConnection(latus) { underscored: true, }); }); - const map = latus.invokeComposed('@latus/db/models.decorate', Models); - debug('composed: %O', Object.keys(map)); Object.entries(map).forEach(([, Model]) => Model.associate(map)); Object.entries(map).forEach(([, Model]) => Model.sync()); + // eslint-disable-next-line no-param-reassign latus.config['%models'] = map; // eslint-disable-next-line no-constant-condition while (true) {