laraguy25's avatar

Pivot table question

I'm trying to figure out the best way to structure a database for cars, features and feature values.

For example a "Honda Civic" is a car. "Engine" is a car feature. "V8" is a car feature value.

Is it improper to use a pivot table for this since car_feature_value doesn't only tied car and car feature together but also has a value field for the car feature?

car: id, name, created_at, updated_at

car_feature: id, name

car_feature_value: id, car_id, car_feature_id, value, created_at, updated_at

0 likes
3 replies
tisuchi's avatar

@laraguy25 If I understand your question, it seems you are on the right track.

What exactly is your question here?

Snapey's avatar

another option is the car has many features

feature has a type and a value. value is a property of feature. feature_type is a table of standardised feature names like engine, doors, aircon etc. Features might be in categories, interior, drive train, exterior so that features can be grouped

so rather than

car ... feature ... value

its

car ... feature 
           |.. feature_type 
                   |.. feature_type_category

Please or to participate in this conversation.