Re: how to link different but related tables

From: Jerry Stuckle <jstucklex_at_attglobal.net>
Date: Sun, 20 Mar 2016 17:39:29 -0400
Message-ID: <ncn54i$ida$1_at_jstuckle.eternal-september.org>


On 3/20/2016 5:14 PM, mireero wrote:
> On 03/13/2016 03:11 PM, Jerry Stuckle wrote:

>>> Or (without eval), putting all different actions in a big switch/case:
>>> >
>>> >switch($product_type) {
>>> >case 'dematerialized':
>>> >     // Actions to build html code related to dematerialized product
>>> >     break;
>>> >case 'physical':
>>> >     // Idem for physical items
>>> >     break;
>>> >...
>>> >}
>>> >
>> Terrible.  Code should never depend on database design.
>>

>
> Thanks everyone for hints/info.
>
> I still have one question, I don't really understand the above comment.
>
> I do understand that a database's purpose is to store information.
> So I think what Jerry means is that an application design shouldn't be
> dictated by the design of the database.
>
> Maybe keep the database design as "generic" as possible so as to allow a
> maximum of "liberty" in the thinking of the application.
> Separate data storage and logic.
>
> I think that's the idea behind this comment.
>
> Nevertheless, I still don't understand because those 2 parts are closely
> related.
>
> I have to take actions that will depend on the kind of product sold
> (like send a parcel or provide a file link). And that info has to be in
> the database.
>
> Anything I'm missing?

Your database is not normalized. Read up on normalization. For instance, color would not be dependent on size - they are both attributes, but they are unrelated to each other. A better way would be to have a color table with another table linking specific color(s) to the object. Same thing with size. For software, you could have a table with the actual file location on your system (which, obviously, you don't pass on to them, but use for downloading).

Don't think if it as "hard products" and "soft products". Rather, think if them as products, with attributes. Each type of attribute is a table. Yes, it can mean a bunch of LEFT JOINs - but in the long run your code and database will be much easier to maintain.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex_at_attglobal.net
==================
Received on Sun Mar 20 2016 - 22:39:29 CET

Original text of this message