Jump to content

How to manage databases with groups of somewhat related items


CrimpJiggler

Recommended Posts

I have a database with compounds, plants, preparations and products. They're all connected because they're all substances and sometimes a plant with contain some of the compounds, or a preparation will contain some of the plants etc. I'm trying to figure out if its better to lump them into one table, give them their own tables or what. What I did was something in between:

68e483dbe2d38e7f9e7aa7261916eef2.png

I created an items table which contains only the fields that all these things contain, then I made extra tables for compounds, plants, products etc. that contains all the additional data specific to those groups (i.e. melting points for compounds, natural habitat for plants, manufacturer for products etc. and then use that code (com, pla, pro) to join those additional tables. See the way there are 2 ID numbers before the item name, the first is the item ID, and the second is the ID for the additional table so for example rosemarinic acid is item 31 but compound 96.

 

I'm switching over to cakephp right now so if this is a bad approach to DB management I might as well change things now. I also have a relational table which connects these 4 groups together, so for example opium there contains morphine, codeine and papaverine, and its found in the papaver somniferum plant so I need to make all those links. Should I stick to this way of doing things?

Edited by CrimpJiggler
Link to comment
Share on other sites

I think I would have separate tables for plants, compounds, etc, and then have a cross referencing table. So for instance if you have plant #1, and it is related to compound #12, you would have a reference in the cross reference table:

a_type = plant
a_id   = 1
b_type = compound
b_id   = 12

You would end up with multiple rows if plant #1 had a few compounds, but this would make it easy to do cross references because if you query the cross reference table you can see that plant 1 is related to compound 12 ( or compound 12 is related to plant 1 ).

 

Maybe somebody else has a better idea, but your original proposed solution seems like it is messy to me.

Link to comment
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.