Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/ar/preloader.rb

Instance Method Summary collapse

Instance Method Details

#preload(*args) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# 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