feat(associations): many-to-many associations

fix(associations): fix association queries, must use `include` instead of ForeignKey
fix(error): error decorator was missing await, which prevented it from catching errors
fix(error): console.error the error
refactor(crud): don't use `request.models[name]`, use the model directly
chore: README added
This commit is contained in:
Mahdi Dibaiee
2016-01-19 10:03:29 +03:30
parent bae6820e64
commit 52ad030d0d
8 changed files with 152 additions and 35 deletions

View File

@ -37,16 +37,23 @@ const register = (server, options = {}, next) => {
associations.oneToOne(server, target, source, options);
}
if (sourceType === 'BelongsTo' && (targetType === 'HasMany')) {
if (sourceType === 'BelongsTo' && targetType === 'HasMany') {
associations.oneToOne(server, source, target, options);
associations.oneToOne(server, target, source, options);
associations.oneToMany(server, target, source, options);
}
if (sourceType === 'BelongsToMany' && targetType === 'BelongsToMany') {
associations.oneToOne(server, source, target, options);
associations.oneToOne(server, target, source, options);
associations.oneToMany(server, source, target, options);
associations.oneToMany(server, target, source, options);
}
} catch(e) {
// There might be conflicts in case of models associated with themselves and some other
// rare cases.
}
console.log(sourceName.singular, sourceType, targetName.singular, ' & ', targetName.singular, targetType, sourceName.singular);
}
}