Class: Reflections::Remappers::BelongsTo

Inherits:
Reflections::Remapper show all
Defined in:
lib/reflections/remappers/belongs_to.rb

Constant Summary

Constants inherited from Reflections::Remapper

Reflections::Remapper::REMAPPERS

Instance Attribute Summary collapse

Attributes inherited from Reflections::Remapper

#from_obj, #to_obj

Instance Method Summary collapse

Methods inherited from Reflections::Remapper

#initialize

Constructor Details

This class inherits a constructor from Reflections::Remapper

Instance Attribute Details

#remapperObject (readonly)

Returns the value of attribute remapper.



5
6
7
# File 'lib/reflections/remappers/belongs_to.rb', line 5

def remapper
  @remapper
end

Instance Method Details

#remap(ar_classes, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/reflections/remappers/belongs_to.rb', line 7

def remap(ar_classes, &block)
  ar_classes.each do |ar_class|
    associations_for_class(ar_class).each do |association|
      foreign_key = association.foreign_key || "#{association.name}_id"
      ar_class.where(foreign_key => from_obj).each do |record|
        update_record_or_yield record, association, &block
      end
    end
  end
end