Menu structure with multiple parents?

Hello,

my current menu is based on acts_as_tree which worked just fine so far
but now I need some menu items being shown under more than one parent.

Example:
menu1
-submenu1
-submenu2
menu2
-submenu1
-submenu3
menu3
-submenu4
-submenu1

I thought about a habtm on the menu model but don’t think that’s a good
idea. Does anyone know a proper solution to this?

What do you guys think of:
has_and_belongs_to_many :parents, :class_name => “Menu”,
:association_foreign_key => “parent_id”, :join_table => “menus_parents”

On Jul 15, 2:03 am, Heinz S. [email protected] wrote:

What do you guys think of:
has_and_belongs_to_many :parents, :class_name => “Menu”,
:association_foreign_key => “parent_id”, :join_table => “menus_parents”

I think it’s astoundingly bad UI to have identical options in more
than one place - but that’s just my opinion.

Unless your Menu model is exceptionally complicated, is it really
worth the significant boost in both code and SQL complexity just to
support this (hopefully uncommon) edge case? DRY is great, but there’s
a point of diminishing (if not negative) returns…

As to the technical side of the question, you’d want to use a real
join model (with has_many :through). How else could you keep track of
the position of the repeated items in each of the parent menus?

–Matt J.

You’re right, has_many :through is probably a better solution but if you
don’t like that approach what would yours look like?

Thanks!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs