in reply to Inheritance, Class::DBI and POOP

I don't know much about Class::DBI, but I have spent some time over the OO <-> relational DBMS questions.

The three classical solutions for subclassing are:

  1. One common table for all subclasses, containing all attributes that appear in any of the subclasses;
  2. One table for the common attributes and one for each class. The class-table contains the class-specific attributes, plus a pointer-field to the record in the common class (this is my favourite);
  3. One table for each class, each table having columns for both common and class-specific attributes.

In the first and second case, a query over the common attributes will probably map to a single QUERY statement. In the third case, you have to repeat the query for all subclasses.

In case 1/2, you will probably have to deal with casting issues, since after getting the common attributes you should determine what class they belong to and retrieve the remaining attributes. This can be transparent and often avoid one more query if the mapping layer implements lazy attributes. In case 3, you would not face this problem, because each query would only deal with one class.

Best regards

Antonio Bellezza

N.B. Throughout the post, "probably" is short for "in most conditions, depending on implementation of the mapping layer".

The stupider the astronaut, the easier it is to win the trip to Vega - A. Tucket