class Generators::Hobo::Migration::HabtmModelShim

Public Class Methods

from_reflection(refl) click to toggle source
# File lib/generators/hobo/migration/migrator.rb, line 7
def self.from_reflection(refl)
  result = self.new
  result.join_table = refl.options[:join_table].to_s
  result.foreign_keys = [refl.foreign_key.to_s, refl.association_foreign_key.to_s].sort
  # this may fail in weird ways if HABTM is running across two DB connections (assuming that's even supported)
  # figure that anybody who sets THAT up can deal with their own migrations...
  result.connection = refl.active_record.connection
  result
end

Public Instance Methods

field_specs() click to toggle source
# File lib/generators/hobo/migration/migrator.rb, line 25
def field_specs
  i = 0
  foreign_keys.inject({}) do |h, v|
    # some trickery to avoid an infinite loop when FieldSpec#initialize tries to call model.field_specs
    h[v] = HoboFields::Model::FieldSpec.new(self, v, :integer, :position => i)
    i += 1
    h
  end
end
index_specs() click to toggle source
# File lib/generators/hobo/migration/migrator.rb, line 39
def index_specs
  []
end
primary_key() click to toggle source
# File lib/generators/hobo/migration/migrator.rb, line 35
def primary_key
  false
end
table_exists?() click to toggle source
# File lib/generators/hobo/migration/migrator.rb, line 21
def table_exists?
  ActiveRecord::Migration.table_exists? table_name
end
table_name() click to toggle source
# File lib/generators/hobo/migration/migrator.rb, line 17
def table_name
  self.join_table
end