Class: ActiveRecord::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/appcelerator/migration.rb

Class Method Summary collapse

Class Method Details

.add_foreign_key(from_table, from_column, to_table) ⇒ Object



3
4
5
6
# File 'lib/appcelerator/migration.rb', line 3

def self.add_foreign_key(from_table, from_column, to_table)
		constraint_name = "fk_#{from_table}_#{from_column}"		
		execute %{ALTER TABLE #{from_table} ADD CONSTRAINT #{constraint_name} FOREIGN KEY (#{from_column}) REFERENCES #{to_table}(id)}
end