I have a trouble trying to get this working. I have an Item model, and each Item can have other items or nothing.
So is this possible or do I need to do some magic?
I have a trouble trying to get this working. I have an Item model, and each Item can have other items or nothing.
So is this possible or do I need to do some magic?
You can either use the acts as tree plugin or build it your self:
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
There's probably some AR builtins or libs plugins / gems to handle most non-bizarre use cases, but: Not clear if you're talking about a
or, the messiest thing, a - Entity-Attribute-Value table (EAV) design