Module: Jat::Plugins::BaseActiverecordPreloads::ActiverecordRelation::ClassMethods

Included in:
Jat::Plugins::BaseActiverecordPreloads::ActiverecordRelation
Defined in:
lib/jat/plugins/base/base_activerecord_preloads/lib/preloader.rb

Instance Method Summary collapse

Instance Method Details

#fit?(objects) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/jat/plugins/base/base_activerecord_preloads/lib/preloader.rb', line 52

def fit?(objects)
  objects.is_a?(ActiveRecord::Relation)
end

#preload(objects, preloads) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/jat/plugins/base/base_activerecord_preloads/lib/preloader.rb', line 56

def preload(objects, preloads)
  if objects.loaded?
    array_objects = objects.to_a
    Loader.call(array_objects, preloads)
    objects
  else
    objects.preload(preloads).load
  end
end