Skip to content

Instantly share code, notes, and snippets.

@scottkf
Created October 31, 2011 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottkf/1327498 to your computer and use it in GitHub Desktop.
Save scottkf/1327498 to your computer and use it in GitHub Desktop.
Self-referential rails example
class CreatePeople < ActiveRecord::Migration
def change
create_table :people do |t|
t.string :name
t.timestamps
end
end
end
class CreatePersonRelationships < ActiveRecord::Migration
def change
create_table :person_relationships do |t|
t.integer :parent_id
t.integer :child_id
t.timestamps
end
end
end
ActiveRecord::Schema.define(:version => 20100401133415) do
create_table "people", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "person_relationships", :force => true do |t|
t.integer "parent_id"
t.integer "child_id"
t.datetime "created_at"
t.datetime "updated_at"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment