Skip to content

Commit

Permalink
add cache dependency to join table
Browse files Browse the repository at this point in the history
  • Loading branch information
gwilymhumphreys committed Mar 27, 2024
1 parent 6ba5faf commit aac5a4b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/stein-orm-rest/src/lib/JoinTableControllerSingleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit aac5a4b

Please sign in to comment.