Created
June 30, 2011 09:43
-
-
Save lindblom/1055936 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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