Jump to content

Recommended Posts

let's say you have a book of recipes, and you want to make database to hold this information..

you have [b]Categories[/b] of recipes,
then [b]subCategories[/b]
and final [b]Recipes[/b], so nothing complicated..
BUT
some categories do not have subcategories, only recipes that belong to them..

so i know you relate categories to subcategories as one to many, and subcategories to recipes as one to many or many to many (as one recipe may exist in more than one subcategory) and that's all ok..
but HOW TO relate now categories that do not have subcategories to recipes table..when in recipes table is needed field from subcategories (enforce referential integrity)..

thank you very much
Branko
Link to comment
https://forums.phpfreaks.com/topic/9119-relationship/
Share on other sites

[!--quoteo(post=371671:date=May 5 2006, 02:51 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 5 2006, 02:51 PM) [snapback]371671[/snapback][/div][div class=\'quotemain\'][!--quotec--]
That's the wrong way to think about it -- you only need two tables, recipes & categories. That relationship is simple; then, simply store a parent_category_id in the categories table, and have the top-level ones have a NULL parent. That's it.
[/quote]
yes ,but then you would have repeating parent_category_id field values for all recipes that belong to same category, and that way it would be hard to maintain database in future..
Link to comment
https://forums.phpfreaks.com/topic/9119-relationship/#findComment-33821
Share on other sites

[!--quoteo(post=371797:date=May 6 2006, 05:47 AM:name=branquito)--][div class=\'quotetop\']QUOTE(branquito @ May 6 2006, 05:47 AM) [snapback]371797[/snapback][/div][div class=\'quotemain\'][!--quotec--]
yes ,but then you would have repeating parent_category_id field values for all recipes that belong to same category, and that way it would be hard to maintain database in future.. [/quote]

Yes, you would have repeating parent_category_id field values - but how does that make it hard to maintain your database? That's actually very standard database design...
Link to comment
https://forums.phpfreaks.com/topic/9119-relationship/#findComment-33837
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.