Module: ActiveRecord::PreloadBlock

Included in:
Relation
Defined in:
lib/active_record/preload_block.rb

Instance Method Summary collapse

Instance Method Details

#preload(*args, &block) ⇒ Object



5
6
7
8
# File 'lib/active_record/preload_block.rb', line 5

def preload(*args, &block)
  check_if_method_has_arguments!(:preload, args) unless block
  spawn.preload!(*args, &block)
end

#preload!(*args, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/active_record/preload_block.rb', line 10

def preload!(*args, &block)
  self.preload_values += args if args.present?

  if block
    on_load! do |records|
      ActiveRecord::Associations::Preloader.new.instance_exec(records, &block)
    end
  end

  self
end