views:

43

answers:

1

Restaurants have buffets. and Buffets have different spreads. i wanna enable photo and comments on each dish on the Buffet. not sure which is the best way to store them in Database

What i have done ?

I have a Restaurant Db that stores the general information of the REst. Dishes DB that stores Dishes of the Resturants. each dish is again mapped to a category like Starters, Drinks, Main Course.

Now how to store the Dishes as a part of a Buffet of a Restaurant in a normalized way.

+1  A: 

You need a Restaurant table with a unique primary key REST_ID and other Restaurant attributes (like name and location, name of chef)

You need a Buffet table with the primary key (REST_ID, BUFFET_ID), and other Buffet attributes such as name ( "Salad Bar," "Smorgasbord," or "Sweets" for example.)

You need a Dish table with the primary key (REST_ID, BUFFET_ID, DISH_ID) and other attributes such as name ("Potato Salad," "Buttered Nan")

You need a Photos table with the primary key (REST_ID, BUFFET_ID, DISH_ID, PHOTO_ID) and other attributes, for example a pathname or blob for the photo itself, and a caption.

You need a Reviews table with the primary key (REST_ID, BUFFET_ID, DISH_ID, REVIEW_ID).

Notice that there's a design choice in this data model: it is not possible for the same dish to appear on two different buffets. Nor is it possible for the same buffet to appear in two different restaurants. That is, the data is strictly hierarchical:

One restaurant: zero, one, or more buffets
One buffet: zero, one or more dishes
One dish: zero, one or more photos
One dish: zero, one or more reviews

This makes sense for a review application. If you get food poisoning from the egg salad in Restaurant A, it makes no sense for your negative review of the dish to appear under Restaurant B.

Here are some example rows for each table.

Restaurant (REST_ID, Name, Chef)

1 "McDonalds" Ronald
2 "Julia's Place" Julia
3 "Ritz Carlton Dining Room" Jack

Buffet (REST_ID, BUFFET_ID, Name)

2 1 "Soup Bar"   (this is the soup bar at Julia's place)
2 2 "Salad Bar"  (the salad bar at Julia's place)
3 1 "Cold Breakfast"  (the cold breakfast bar at the hotel dining room)
3 2 "Sweets"  ( the dessert bar at the hotel dining room)

Dish: (REST_ID, BUFFET_ID, DISH_ID, name and category)

2 1 1 "Minestrone" "Soup"
2 1 2 "French Onion" "Soup"
2 1 3 "Vegetarian Barley" "Soup"
2 1 4 "Saltines" "Crackers"
3 1 1 "Melon" "Fruit"
3 1 2 "Strawberry" "Fruit"
3 1 3 "Blueberry Muffin" "Bread"
3 1 4 "Multigrain Bread" "Bread"
3 1 5 "Corn Flakes" "Cereal"
3 1 6 "Orange Juice" "Drink"
3 1 7 "Milk" "Drink"

etc.

Ollie Jones
thanks Ollie, small problem in understanding the Buffet Table. Will it hold the name of the Buffet or the various categories.
Harsha M V
There's a Buffet row for each different buffet spread. (Some restaurants have more than one buffet.) It contains the name of the buffet. If I were you I would make the category (starter, main-dish, etc) of each dish a column of the Dish table.
Ollie Jones
i have categories. but i have another table for that. any help on how to name these buffets in their table.
Harsha M V
I tried to address your question in my edit, but I am not sure I understand it completely.
Ollie Jones
Yes,. In the Buffet Table.. Buffet ID ... its not unique.. thats my question... where does that refer to :D hope i am not confusing u further
Harsha M V
You certainly can use a unique Buffet_id ... but with the primary keying system I have proposed it is not necessary. That is because the pk is (rest_id, buffet_id) concatenated.
Ollie Jones