The model of the (PHP & MySQL based) Zend Framework 2 application I’m currently working on contains a inheritance similar to the one described here.
To map this to the database I’m using the Class Table Inheritance design pattern.
I’m cheating a bit and let the “super-entity” (i.e., the supertype) know, which type of “sub-entity” (i.e., the subtype) belongs to it. That means, the “super-entity” has a property (i.e., attribute or column) named
type. The value is camel-cased (for an easier usage in the application). The table names are always underscored.
Here is a diagram depicting my database structure
And a diagram displaying class models for my application program objects
The problem is now the retrieving. When I want to get a
id=123, I don't know at first, which
type it has and hence which
car_* table I have to
JOIN. Well, I could workaround it, either
JOINing every time all
car_* tables or making two request (when the first one is something like a “pre-request” and is used to get the
SELECT type FROM car;), but I’m sure, there must be a better solution.
TABLE with a variable name, that equals to a selected value in another