Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've done something like this for publisher trying to attach repair procedures to a product. The product is identified by a four-part primary key: Year, Make, Model, Engine, or YMME, and the vehicles table looked like this (simplified):</p> <pre><code>VEHICLES year integer make varchar model varchar engine varchar </code></pre> <p>The PARTS table has to be linked to an entity in the VEHICLES table. A part might work with a specific year and make and model, but not when a specific engine was installed.</p> <p>In your case, you have to decide what constellation of attributes uniquely identifies a bicycle. If you're tracking bikes from multiple makers, you need MAKE. If things change from year to year, you need YEAR. If there is a difference from model to model, you need MODEL. If, say, a part will work if the frame is aluminum but not if the frame is steel, you'd need FRAME_MATERIAL or FRAME_GAUGE as well, in place of ENGINE, or you'd need a separate model one for aluminum, the other for steel.</p> <pre><code>VEHICLES year make model frame </code></pre> <p>Then you could simply have an intermediary table:</p> <pre><code>VEHICLE_PARTS partid integer foreign key references PARTS year make model frame ... </code></pre> <p>or</p> <pre><code>VEHICLE_PARTS partid integer foreign key references PARTS year make model (frame material is handled by a separate model) </code></pre> <p>Your structure has to answer the question: Will this part work with <em>that</em> bike? The mere presence of the partid in the VEHICLE_PARTS table should imply, Yes it does. You really want to avoid having an Exceptions field in the VEHICLE_PARTS table where there is some human-readable notation that says the part is incompatible with the bike in question when rams-horn handlebars are used. You should really create a separate model to handle things like that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload