Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Has_one_through_association error and Application cache configuration #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/second_level_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def acts_as_cached(options = {})
end

def second_level_cache_enabled?
!!@second_level_cache_enabled
if defined?(Rails)
!!@second_level_cache_enabled && ::Rails.application.config.cache_classes
else
!!@second_level_cache_enabled
end
end

def without_second_level_cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module HasOneAssociation

def find_target_with_second_level_cache
return find_target_without_second_level_cache unless association_class.second_level_cache_enabled?
return find_target_without_second_level_cache if self.class == ::ActiveRecord::Associations::HasOneThroughAssociation
cache_record = association_class.fetch_by_uniq_key(owner[reflection.active_record_primary_key], reflection.foreign_key)
return cache_record.tap{|record| set_inverse_instance(record)} if cache_record

Expand Down