fix: model is not null

This commit is contained in:
chenos 2020-12-17 21:47:23 +08:00
parent aef6b85736
commit 59db7a34dc
2 changed files with 8 additions and 4 deletions

View File

@ -239,7 +239,10 @@ export default class Database {
}
for (const name of names) {
// @ts-ignore
sequelize.modelManager.addModel(this.getModel(name));
const model = this.getModel(name);
if (model) {
sequelize.modelManager.addModel(model);
}
}
await sequelize.sync(restOptions);
await sequelize.close();

View File

@ -238,12 +238,13 @@ export class Table {
*/
public getRelatedTableNames(): Set<string> {
const names = new Set<string>();
names.add(this.options.name);
this.options.name && names.add(this.options.name);
for (const association of this.associations.values()) {
const target = association.getTarget();
names.add(target);
target && names.add(target);
if (association instanceof BELONGSTOMANY) {
names.add(association.getThroughName());
const throughName = association.getThroughName();
throughName && names.add(throughName);
}
}
return names;