Sunday, November 29, 2009

Association problem

I am trying to make some associations with a restaurant menu. I have
five tables and they are all linked, although not directly. How do get
info from all tables if some tables aren't in direct relation to the
"calling table"?

Here is my setup:

menu_items
-id
-name
-price

menu_types: ( has only Lunch & Dinner)
-id
-name

menu_item_types (associates each menu item with either lunch or
dinner)
-menu_item_id
-menu_item_type_id

menu_subtypes: ( has Appetizers, Soups, Pasta, etc...)
-id
-name

menu_item_types (associates each menu item with either Appetizers,
Soups, Pasta, etc...)
-menu_item_id
-menu_item_type_id


Basically, I want to be able to select all the info from all tables.
The associations I have now are:
MenuItem hasOne (MenuItemType, MenuItemSubtype)
MenuType hasOne (MenuItemType)
MenuItemType belongsTo (MenuItem, MenuType)
MenuSubtype hasOne (MenuItemSubtype)
MenuItemSubtype belongsTo (MenuItem, MenuSubtype)

From MenuItemsController, I have no problem getting MenuItem,
MenuItemType, and MenuItemSubtype
but I can't get MenuType or MenuSubtype. How do I get those?

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: