diff --git a/packages/stein-orm-rest/src/lib/JoinTableControllerSingleton.js b/packages/stein-orm-rest/src/lib/JoinTableControllerSingleton.js index 0f7c783..51c5626 100644 --- a/packages/stein-orm-rest/src/lib/JoinTableControllerSingleton.js +++ b/packages/stein-orm-rest/src/lib/JoinTableControllerSingleton.js @@ -38,7 +38,15 @@ class JoinTableControllerSingleton { const joinTableOptions = _.clone(options) joinTableOptions.route = path.join(routeRoot, joinTableEndpoint) if (joinTableOptions.route[0] !== '/') { joinTableOptions.route = `/${joinTableOptions.route}` } - if (this.joinTables[joinTableOptions.route]) return // already exists + + // join table has already been created, make sure this controller is added to the cache dependencies and bail + const existingJoinTable = this.joinTables[joinTableOptions.route] + if (existingJoinTable) { + if (existingJoinTable.cache && existingJoinTable.cache.createHash) { + existingJoinTable.cache.cascade = _.uniq([...(existingJoinTable.cache.cascade || []), existingJoinTable.cache.createHash(options)]) + } + return + } for (const _key of ['whitelist', 'templates', 'defaultTemplate']) { delete joinTableOptions[_key]