Sha256: a0b6157d069815c8e8ce75c7975685c20a2dab81cfee26f916d78c46b9813d85

Contents?: true

Size: 1.09 KB

Versions: 11

Compression:

Stored size: 1.09 KB

Contents

module SecondLevelCache
  module ActiveRecord
    module Associations
      module HasOneAssociation
        def find_target
          return super unless klass.second_level_cache_enabled?
          return super if reflection.options[:through] || reflection.scope
          # TODO: implement cache with has_one through, scope

          owner_primary_key = owner[reflection.active_record_primary_key]
          if reflection.options[:as]
            keys = {
              reflection.foreign_key => owner_primary_key,
              reflection.type => owner.class.base_class.name
            }
            cache_record = klass.fetch_by_uniq_keys(keys)
          else
            cache_record = klass.fetch_by_uniq_key(owner_primary_key, reflection.foreign_key)
          end

          if cache_record
            return cache_record.tap { |record| set_inverse_instance(record) }
          end

          record = super
          return nil unless record

          record.tap do |r|
            set_inverse_instance(r)
            r.write_second_level_cache
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
second_level_cache-2.3.3 lib/second_level_cache/active_record/has_one_association.rb
second_level_cache-2.3.2 lib/second_level_cache/active_record/has_one_association.rb
second_level_cache-2.3.1 lib/second_level_cache/active_record/has_one_association.rb
second_level_cache-2.3.0 lib/second_level_cache/active_record/has_one_association.rb
second_level_cache-2.3.0.beta lib/second_level_cache/active_record/has_one_association.rb
second_level_cache-2.2.6 lib/second_level_cache/active_record/has_one_association.rb
second_level_cache-2.2.5 lib/second_level_cache/active_record/has_one_association.rb
second_level_cache-2.2.4 lib/second_level_cache/active_record/has_one_association.rb
second_level_cache-2.2.3 lib/second_level_cache/active_record/has_one_association.rb
second_level_cache-2.2.2 lib/second_level_cache/active_record/has_one_association.rb
second_level_cache-2.2.1 lib/second_level_cache/active_record/has_one_association.rb