Recursive Model in Rails

I have problems trying to get this to work. I have an Item model, and each item can have other items or nothing.

So is this possible or do I need to do magic?

+4
source share
3 answers

You can use it as a tree plugin or create it yourself:

belongs_to :parent, :foreign_key => "parent_id", :class_name => "Item" has_many :children, :foreign_key => 'parent_id', :class_name => 'Item', :order => 'created_at ASC', :dependent => :delete_all 
+6
source

Check out the associative association .

0
source

There are probably some built-in or built-in AR plugins to handle most non-standard use cases, but: It's not clear if you are talking about

  • table join / Actve record association (heterogeneous relationships, two or three tables)
  • nested set / act _as_tree, (tree of similar objects in one table) or
  • Inheritance of separate tables, several heterogeneous objects in one table

or, worst of all, - Attribute Attribute Table Design (EAV)

http://en.wikipedia.org/wiki/Entity-Attribute-Value_model

0
source

All Articles