Skip to content

Commit

Permalink
cache key breaks when receiving a belongs to reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
rpbaltazar committed Sep 12, 2021
1 parent 0938d58 commit 06ad2d6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/apartment/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def cached_find_by_statement(key, &block)
cache_key = if key.is_a? String
"#{Apartment::Tenant.current}_#{key}"
else
[Apartment::Tenant.current] + key
# NOTE: In Rails 6.0.4 we start receiving an ActiveRecord::Reflection::BelongsToReflection
# as the key, which wouldn't work well with an array.
[Apartment::Tenant.current] + Array.wrap(key)
end
cache = @find_by_statement_cache[connection.prepared_statements]
cache.compute_if_absent(cache_key) { ActiveRecord::StatementCache.create(connection, &block) }
Expand Down

0 comments on commit 06ad2d6

Please sign in to comment.