abstract class with Class::DBI
[prev]
[thread]
[next]
[Date index for 2004/10/20]
I've got a bunch of activities, they are of different types like e-mail,
SMS, and registration. They are represented by an abstract class, called
Activity, with subclasses for each type, called ActivityEmail, ActivitySms,
and ActivityReg. I'm trying to work out how to store them using Class::DBI.
I'm using PostgreSQL for the database, fields that are common to all the
types are stored the activity table.
create table activity (
id serial primary key,
title varchar(50),
activitytype character(10) check (activitytype in ('email', 'sms', 'reg'));
activitydate date,
);
create table activity_email (
activity integer primary key references activity(id),
subject varchar(80),
body text,
whofrom varchar(80),
whoto varchar(80),
);
create table activity_sms (
activity integer primary key references activity(id),
message varchar(160)
)
create table activity_reg (
activity integer primary key references activity(id),
purpose varchar(15) check (purpose in ('General', 'Competition')),
);
For each activity there is one entry in the activity table, and one in the
table for that specific type.
Column definitions are provided by Class::DBI::Loader, here is the
Class::DBI code to describe the classes:
package MyApp::Activity;
__PACKAGE__->might_have(activity_email => 'VV::ActivityEmail');
__PACKAGE__->might_have(activity_sms => 'VV::ActivitySms');
__PACKAGE__->might_have(activity_reg => 'VV::ActivityReg');
package MyApp::ActivityEmail;
use base qw(MyApp::Activity);
__PACKAGE__->has_a(activity => 'MyApp::Activity');
package MyApp::ActivitySms;
use base qw(MyApp::Activity);
__PACKAGE__->has_a(activity => 'MyApp::Activity');
package MyApp::ActivityReg;
use base qw(MyApp::Activity);
__PACKAGE__->has_a(activity => 'MyApp::Activity');
Does all of this look right, or should I be doing it another way?
|
(message missing)
|
|
|
abstract class with Class::DBI
Edward Betts 15:09 on 20 Oct 2004
|