fix: attributes after compose

This commit is contained in:
cha0s 2020-12-06 08:49:49 -06:00
parent 7434d1bc5d
commit 44cd1c26e2

View File

@ -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) {