Module: Immigrant::ForeignKeyDefinition

Includes:
Foreigner::SchemaDumper::ClassMethods
Defined in:
lib/immigrant/foreign_key_definition.rb

Overview

add some useful stuff to foreigner’s ForeignKeyDefinition TODO: get more of this into foreigner so we don’t need to monkey patch

Instance Method Summary collapse

Instance Method Details

#hash_keyObject



13
14
15
# File 'lib/immigrant/foreign_key_definition.rb', line 13

def hash_key
  [from_table, options[:column]]
end

#initialize(from_table, to_table, options, *args) ⇒ Object



7
8
9
10
11
# File 'lib/immigrant/foreign_key_definition.rb', line 7

def initialize(from_table, to_table, options, *args)
  options ||= {}
  options[:name] ||= "#{from_table}_#{options[:column]}_fk"
  super(from_table, to_table, options, *args)
end

#to_ruby(action = :add) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/immigrant/foreign_key_definition.rb', line 17

def to_ruby(action = :add)
  if action == :add
    dump_foreign_key(self)
  else
    "remove_foreign_key #{from_table.inspect}, " \
    ":name => #{options[:name].inspect}"
  end
end