Skip to content

Instantly share code, notes, and snippets.

@lindblom
Created June 30, 2011 09:43
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 lindblom/1055936 to your computer and use it in GitHub Desktop.
Save lindblom/1055936 to your computer and use it in GitHub Desktop.
# the migration
class CreateForumPosts < ActiveRecord::Migration
def self.up
create_table :forum_posts do |t|
t.string :title
t.text :message
t.integer :parent_id
t.timestamps
end
end
def self.down
drop_table :forum_posts
end
end
# the model
class ForumPost < ActiveRecord::Base
has_many :children, :class_name => "ForumPost", :foreign_key => :parent_id, :select => "id, parent_id, title"
belongs_to :parent, :class_name => "ForumPost", :foreign_key => :parent_id, :select => "id, parent_id, title"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment