abstract class with Class::DBI

[prev] [thread] [next] [Date index for 2004/10/20]

From: Edward Betts
Subject: abstract class with Class::DBI
Date: 15:09 on 20 Oct 2004
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

Re: abstract class with Class::DBI
Tom Hukins 16:40 on 20 Oct 2004

Re: abstract class with Class::DBI
William McKee 13:00 on 21 Oct 2004

Re: abstract class with Class::DBI
Tom Hukins 14:17 on 21 Oct 2004

Re: abstract class with Class::DBI
Perrin Harkins 16:09 on 22 Oct 2004

Re: abstract class with Class::DBI
Tony Bowden 14:41 on 21 Oct 2004

Re: abstract class with Class::DBI
William McKee 18:54 on 21 Oct 2004

Re: abstract class with Class::DBI
Michael 19:17 on 21 Oct 2004

Re: abstract class with Class::DBI
Andreas Fromm 07:00 on 21 Oct 2004

Re: abstract class with Class::DBI
William McKee 19:42 on 21 Oct 2004

Re: abstract class with Class::DBI
Kingsley Kerce 20:01 on 21 Oct 2004

Re: abstract class with Class::DBI
Perrin Harkins 16:14 on 22 Oct 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52