Class: PireLoader::Loaders::Singular

Inherits:
Object
  • Object
show all
Defined in:
lib/pire_loader/loaders/singular.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(association) ⇒ Singular

Returns a new instance of Singular.



12
13
14
# File 'lib/pire_loader/loaders/singular.rb', line 12

def initialize(association)
  @association = association
end

Class Method Details

.preload(association) ⇒ Object



8
9
10
# File 'lib/pire_loader/loaders/singular.rb', line 8

def self.preload(association)
  new(association).preload
end

Instance Method Details

#preloadObject



16
17
18
19
20
21
22
# File 'lib/pire_loader/loaders/singular.rb', line 16

def preload
  owner_records.each do |record|
    join_value = record[join_foreign_key]

    record.association(reflection.name).target = associated_records[join_value]
  end
end