Sha256: 1637a471b15d27d4742b47e81d827d14f610e758838de5b827c6d3234525f324
Contents?: true
Size: 1.08 KB
Versions: 2
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module SecondLevelCache module ActiveRecord module Associations module HasOneAssociation def find_target return super unless klass.second_level_cache_enabled? return super if klass.default_scopes.present? || reflection.scope # TODO: implement cache with has_one scope through = reflection.options[:through] record = if through return super unless klass.reflections[through.to_s].klass.second_level_cache_enabled? begin reflection.klass.find(owner.send(through).read_attribute(reflection.foreign_key)) rescue StandardError nil end else uniq_keys = { reflection.foreign_key => owner[reflection.active_record_primary_key] } uniq_keys[reflection.type] = owner.class.base_class.name if reflection.options[:as] klass.fetch_by_uniq_keys(uniq_keys) end return nil unless record record.tap { |r| set_inverse_instance(r) } end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
second_level_cache-2.6.3 | lib/second_level_cache/active_record/has_one_association.rb |
second_level_cache-2.6.2 | lib/second_level_cache/active_record/has_one_association.rb |