Reputation: 40643
I'm re-asking a question that was previously deleted here in SO for not being a "programming question". Hopefully, this is a bit more "programming" than the last post.
First, a few definitions:
2011 Nissan Sentra
2011 Nissan Sentra LX
Generally, a particular vehicle would have a list of, say, available colors or equipment options. So a 2011 Nissan Sentra
may be available in the following colors:
Then, the manufacturer may have made a special color only available to the 2011 Nissan Sentra LX
trim:
If I were building a car website wherein I wanted to capture this information, which of the following should I do:
My gut feeling is that associating it to the model would be sufficient. Associating to trim would mean duplicates (e.g. 2011 Nissan Sentra LX
and 2011 Nissan Sentre SE
would both have "Black" as a color). Trying to associate colors to model and trim might be overkill.
Suggestions?
Upvotes: 4
Views: 1540
Reputation: 95602
If I were building a car website wherein I wanted to capture this information
then you'd have to build a logical model that captured that information. (How hard was that?) And that means you have to model these facts.
Capturing all the known requirements is one thing. Implementing them is another. Once you understand how the colors actually work,
But, as Dr. Phil often says,
Simplifying the known requirements--ignoring the fact that some colors apply only to one or two trim packages--means you design your database to deliberately allow invalid data. Your database might end up with information about a "Pink with Yellow Polka Dots" Nissan Altima, or a "Copper" 2002 Nissan Sentra. (I think Nissan introduced copper in 2004.)
So here's the real question.
That's always going to be application-dependent. A social media site that collected information about your car color would be a lot more tolerant of impossible color choices than a company that sells touch-up paint.
Upvotes: 1
Reputation: 115550
If there are special cases, as you say, where a manufacturer has made a special color only available to a specific trim, like "Pink with Yellow Polka Dots" for the "2011 Nissan Sentra LX trim"
and you want to have those special case stored, you should choose the 2nd option.
So, your relationships would be:
1 manufacturer makes many models
1 model has many trims
1 trim can have many colors and for 1 colour many trims have it
(so you'll need an association table for this relationship)
Manufacturer
1\
\
\N
Model
1\
\
\N
Trim Colour
1\ 1/
\ /
\N /M
TrimColour
With additional information about colours:
One GeneralColour can be named as many Colours by different Manufacturers and one Manufacturer can "baptize" a GeneralColour with various Colour (names)
Manufacturer
1/ 1\
/ \
/N \
Model \ GeneralColour
1\ \ 1/
\ \ /
\N \N /M
Trim Colour
1\ 1/
\ /
\N /M
TrimColour
Thinking more clearly, the extra Manufacturer-Colour
relationship is not needed:
Manufacturer
1\
\
\N
Model GeneralColour
1\ 1/
\ /
\N /M
Trim Colour
1\ 1/
\ /
\N /M
TrimColour
Upvotes: 2
Reputation: 79604
As requested in response to my comment...
I would just make 'color' a free-form text field, possibly with a pre-populated drop-down showing current popular colors in the database. The main advantage is that it makes your DB schema much simpler, and keeps your car model/color researchers from going insane. But it also allows for custom paint jobs that aren't available from the manufacturer at all.
manufacturers
-------------
id
models
------
id
manufacturer (FK to manufacturers.id)
model_name (VARCHAR)
trims
-----
id
model (FK to models.id)
cars
-------
id
trim (FK to trims.id)
year INT
color VARCHAR
Upvotes: 1
Reputation: 41
If different trims for the same model may have different color options (as you imply) then you should associate the color to the trim, otherwise you will have incorrect/incompatible information. aka If "pink with yellow polka dots" is associated to the "2011 Nissan Sentra" model then you will incorrectly show it as an option for trims other than LX.
Upvotes: 2
Reputation: 39480
You're missing the association of the trim to the model; without that, I don't know that you can really properly complete your associations.
Upvotes: 1