On 21 February 2010 05:50, mac
<care4u.jodhpur-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
> hello,
> i have database for dynamic website in which i need to store
> information about each menu and its relationship with other menu.
> it is obvious that each menu can have several submenu but each submenu
> must belong to one and ony one menu.
> so database goes like this
>
>
> Pk_Content_id=>integer
> title =>integer, it is name of menu
> Image_path=>string, path of image
> Content_text=> text contained on click of every menu or description
> fK_parent_content_id => integer , THIS LINKS BACK TO pk_content_id ,as
> is a foreign key
>
>
>
> what i want is to relate pk_content_id and fk_parent_content_id (which
> are in same table)
>
The term you''re looking for is "self referential" - very
handy when
Authors have Readers, or Employees have Managers...
You''ll find lots of tutorials online, but essentially you set it up
thus:
# Menu model
has_many :children, :class_name => "Menu", :foreign_key =>
"parent_content_id" # those ''pk/fk'' prefixes are not
really good from
the Rails conventions
belongs_to :parent, , :class_name => "Menu"
But you might find that one of the "nesting" algorithms suits your
need better - seeing as it seems you might be constantly recurring
down the menus, "awesome_nested_set" might be worth a look.
Hope this helps put you on track.
--
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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.