Module: Miscellany::ArbitraryPrefetch

Defined in:
lib/miscellany/active_record/arbitrary_prefetch.rb

Defined Under Namespace

Modules: ActiveRecordBasePatch, ActiveRecordMergerPatch, ActiveRecordPreloaderPatch, ActiveRecordReflectionPatch, ActiveRecordRelationPatch Classes: PrefetcherContext

Constant Summary collapse

ACTIVE_RECORD_VERSION =
::Gem::Version.new(::ActiveRecord::VERSION::STRING).release
PRE_RAILS_6_2 =
ACTIVE_RECORD_VERSION < ::Gem::Version.new('6.2.0')

Class Method Summary collapse

Class Method Details

.installObject



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/miscellany/active_record/arbitrary_prefetch.rb', line 164

def self.install
  ::ActiveRecord::Base.include(ActiveRecordBasePatch)

  ::ActiveRecord::Relation.prepend(ActiveRecordRelationPatch)
  ::ActiveRecord::Relation::Merger.prepend(ActiveRecordMergerPatch)

  ::ActiveRecord::Associations::Preloader.prepend(ActiveRecordPreloaderPatch)

  ::ActiveRecord::Reflection::AssociationReflection.prepend(ActiveRecordReflectionPatch)

  return unless defined? ::Goldiloader

  ::Goldiloader::AssociationLoader.module_eval do
    def self.has_association?(model, association_name)
      model.association(association_name)
      true
    rescue ::ActiveRecord::AssociationNotFoundError => _err
      false
    end
  end
end