Hi, ok if you replace (…) would it make more sense?
Absolutly!
For a while there I was wondering if you were setting out to program
the matrix.
Abstracting an objects attributes into it’s own table with a one-to-
many (or many-to-many) association between the object and attributes
should be the result of extreme requirement of flexibility an DRYness.
There are alternatives that are also DRY and flexible, but easier to
implement.
Are you familiar with single table inheritance? To me this looks like
a case where it could be a good solution, if the number of vehicle
types are fairly limited. When you have several entities that are
almost the same, but not quite (I.E car, plane, boat), using single
table inheritance is often a great way to reduce repetition. This will
enable you to put all the attributes in one table, and decide which
attributes a vehicle type should use through it’s type.
class Vehicle < ActiveRecord::Base
has_many :models
has_many :ratings
end
Class Car < Vehicle
Class Plane < Vehicle
Class Model
belongs_to :vehicle
What I am suggesting is that you create a super-class called Vehicle,
that has sub-classes for each vehicle type (car, plane, etc). Shared
logic is put in the super-class, individual logic is put in the sub-
class.
I assume subjective dimensions are always the result of a user rating
a vehicle? What to do with rating and subjective dimensions depends on
what you do with Vehicle and factual dimesions. If you decide to use
single table inheritance for the latter then it makes sense to use it
for the former as well. You can remove the subjective dimesions table,
and instead have subjective dimensions as attributes on the ratings
table, and have sub-classes of rating for each sub-class of vehicle so
that you are able to decide which subjective dimensions should come
into play for each vehicle type.
Looking at the design you suggest I can see that you are trying to
make a system that is 100% flexible by being able to decide exactly
what kind of attributes each individual object has. I myself have
never tried to implement a design where I abstracted the attributes
into its own table, having a one-to-many association between the
object and its attributes, so I don’t have any first hand experience
with this. I dont imagine it will be easy. I imagine many challenges
will arise from the fact that attributes can be of different types
(string, integer, boolean, float, etc). If you dont need to any
searching or reporting on the attributes then they could all be stored
as strings, however if you need these things then you need their
types, and implementing the searching and reporting will be very
complex. It is also hard to imagine a system that needs to be this
flexible in data storage without also having complex searching and
reporting requirements.