I wish to set up nested comments, and want to use self-join to set this up.
class Comment < ActiveRecord::Base
has_many :children, :class_name => 'Comment'
#...
end
Now, what sql table structure would I use to set up the has_many self-join?
I’m assuming something like this:
comment_to_comments:
parent_id integer
child_id integer
How do I tell rails to use this table? How do I tell rails that parent_id is the foreign key to reach the parent and the child_id is the foreign key to reach the child?
I suggest you use plugin to implement this feature.like awesome_nested_set or acts_as_tree.