To clarify...

Node is a self-referential object. Here is the class for the Node 
object.

class Node < ActiveRecord::Base
  belongs_to :category
  belongs_to :status

  has_one  :parents,
           :class_name => "NodeGroup",
           :foreign_key => "child_id"
  has_one  :parent, :through => :parents

  has_many :children,
           :class_name => "NodeGroup",
           :foreign_key => "parent_id"
end

And here is the class for the NodeGroup.

class NodeGroup < ActiveRecord::Base
  belongs_to :parent, :class_name => "Node"
  belongs_to :child, :class_name => "Node"
end

The relationship is that Node can have one parent or many children.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to