Skip to content

Instantly share code, notes, and snippets.

@threetee
Created January 12, 2010 09:43
Show Gist options
  • Save threetee/275060 to your computer and use it in GitHub Desktop.
Save threetee/275060 to your computer and use it in GitHub Desktop.
class CreateInterfaces < ActiveRecord::Migration
def self.up
create_table :interfaces do |t|
t.string :name
t.string :description
t.timestamps
end
end
def self.down
drop_table :interfaces
end
end
class CreateConnections < ActiveRecord::Migration
def self.up
create_table :connections do |t|
t.integer :from_interface_id
t.integer :to_interface_id
t.timestamps
end
end
def self.down
drop_table :connections
end
end
class Interface < ActiveRecord::Base
has_one :connection
end
class Connection < ActiveRecord::Base
belongs_to :from_interface, :class_name => 'Interface', :foreign_key => :from_interface_id
belongs_to :to_interface, :class_name => 'Interface', :foreign_key => :to_interface_id
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment