class Array

Public Instance Methods

preload(*args) click to toggle source
# File lib/ar/preloader.rb, line 177
def preload(*args)
  return if args.length == 0

  raise Ar::Preloader::Error.new("Cannot preload. Mixed type lists are not supported.") if (self.map(&:class).uniq.count > 1)
  raise Ar::Preloader::Error.new("Cannot preload. At least one element in array is not an ActiveRecord object.") if (self.reject{|e| e.is_a?(ActiveRecord::Base) }.count > 0)


  args.each do |arg|
    raise Ar::Preloader::Error.new("Cannot find association '#{arg}' on one or more of the ActiveRecord objects.") if (self.reject{|e| Ar::Preloader.check_association_exists(e.class, arg) }.count > 0)
  end

  args.each do |arg|
   Ar::Preloader.preload_association(self, arg) 
  end

  true
end