Sha256: 29d574a483956ff6263d1f46ecc2cbf92c30557c13009bd44291c7d947b35a68
Contents?: true
Size: 882 Bytes
Versions: 16
Compression:
Stored size: 882 Bytes
Contents
# frozen_string_literal: true module ArLazyPreload # ActiveRecord::Relation::Merger patch implementing merge functionality # for lazy preloadable relations module Merger # Enhanced #merge implements merging lazy_preload_values def merge result = super if other.lazy_preload_values.any? if other.klass == relation.klass merge_lazy_preloads else reflect_and_merge_lazy_preloads end end result end private def merge_lazy_preloads relation.lazy_preload!(*other.lazy_preload_values) end def reflect_and_merge_lazy_preloads reflection = relation.klass.reflect_on_all_associations.find do |r| r.class_name == other.klass.name end return unless reflection relation.lazy_preload!(reflection.name => other.lazy_preload_values) end end end
Version data entries
16 entries across 16 versions & 1 rubygems