Re: abstract class with Class::DBI

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

From: Tom Hukins
Subject: Re: abstract class with Class::DBI
Date: 16:40 on 20 Oct 2004
On Wed, Oct 20, 2004 at 04:09:45PM +0100, Edward Betts wrote:
> 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.

The schema and code you use sets has_a relationships on primary keys.
See the note at the end of the has_a section in Class::DBI's
documentation that suggests you avoid this.

I'm working with a similar schema at the moment, and can attest to
"bad things happening" as the documentation claims.

This means you need to do something like:
  Activity->retrieve( $activity_email_id )->title
to retrieve information stored in the 'activity' table when you have
a specific activity object such as one created from the
'activity_email' table.

I also considered storing identical IDs in two columns, one for the
primary key and one for the has_a relationship, but this felt like too
much of a messy hack.

> package MyApp::Activity;
> 
> __PACKAGE__->might_have(activity_email => 'VV::ActivityEmail');
> __PACKAGE__->might_have(activity_sms => 'VV::ActivitySms');
> __PACKAGE__->might_have(activity_reg => 'VV::ActivityReg');

I would import the accessor methods from each of these classes.  For
example, for ActivityEmail, you could write:
  __PACKAGE__->might_have( activity_email => 'VV::ActivityEmail',
  	qw(subject body whofrom whoto) );

This allows you to call $accessor->subject directly, instead of
$accessor->activity_email->subject.

Tom

(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