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:
11
src/index.js
11
src/index.js
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user