Background
I'm building a Private Chef booking service where you can book a Chef to cook you a custom Menu. I'm having trouble creating a SQL db schema that accurately represents the domain while maintaining data integrity.
Requirements
- Customers create a
Booking
by selecting aChef
and aMenu
and choose theMenuItems
they want for eachMenuCourse
- A
Chef
defines a set ofMenuItem
that a customer can choose from to create theirBooking
- A
Menu
is a collection ofMenuCourses
. (ex. AMenu
named "Tasting Menu" is a 6 course meal, where eachMenuCourse
costs between $10-20). - A
Chef
should be able to associate theirMenuItems
with multipleMenus
andMenuCourses
. - A customer
Booking
should contain theChef
the customer selected along with theMenu
(and theMenuItems
) that will be served.Booking
price is determined by theMenu
andMenuCourse
selections (an appetizer costs less than an entree)
Problem
In my current data model, I have the following issues that I'm not sure how to fix:
- it's possible to create a
Booking
withChef
"A", but then have aBookingMenuItem
that references aMenuItem
withChef
"B" (all theBookingMenuItem
for aBooking
should belong to the sameChef
) - a
Booking
references a particularMenu
(which I need for pricing, pricing is based onMenu
andMenuCourse
) however aBookingMenuItem
for thatBooking
could reference a completely differentMenu
orMenuCourse
Is it possible to re-design my db schema to fix the integrity problems I'm having? Or do I just have to implement these checks at the application level. Thanks!
Best Answer