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 // eslint-disable-next-line no-console
const Models = latus.invokeReduce('@latus/db/models'); const Models = latus.invokeReduce('@latus/db/models');
debug('models: %O', Object.keys(Models)); debug('models: %O', Object.keys(Models));
/* eslint-disable no-param-reassign */ const map = latus.invokeComposed('@latus/db/models.decorate', Models);
Object.entries(Models) debug('composed: %O', Object.keys(map));
Object.entries(map)
.filter(([, Model]) => Model.attributes) .filter(([, Model]) => Model.attributes)
.forEach(([, Model]) => { .forEach(([, Model]) => {
Model.init(Model.attributes, { Model.init(Model.attributes, {
@ -48,10 +49,9 @@ export async function createDatabaseConnection(latus) {
underscored: true, 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.associate(map));
Object.entries(map).forEach(([, Model]) => Model.sync()); Object.entries(map).forEach(([, Model]) => Model.sync());
// eslint-disable-next-line no-param-reassign
latus.config['%models'] = map; latus.config['%models'] = map;
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
while (true) { while (true) {