Re: A trigger called when following a 'has_a'

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

From: Charles Bailey
Subject: Re: A trigger called when following a 'has_a'
Date: 15:30 on 20 Jul 2004
--On Tuesday, July 20, 2004 11:22 AM -0400 Charles Bailey 
<bailey@xxxxxx.xxxxx.xxx> wrote:

> and the Origin base class provides the inflate() method to its kids:
>
>   sub inflate {
>     my($id,$parent,$otype) = @_;
>     $otype = '' . $parent->find_column('Origin_type') unless defined
> $otype;
>     my $target = $Otype_to_class{$parent->_attrs($otype)};
>     $target->_simple_bless($id);
>   }
>
> where $Otype_to_class is a mapping in which each subclass registers
> itself as it's loaded.  It's ugly, and perhaps more contorted than you

I should have noted (and perhaps it's obvious), that if you can store the 
actual subclass name in the table, then the mapping is unnecessary; you can 
just say something like

  sub inflate {
    my($id,$parent,$otype) = @_;
    $otype = '' . $parent->find_column('Origin_type') unless defined $otype;
    $otype->new($id); # or $otype->retrieve($id) if it's a CDBI class
 }

and avoid the need for Origin to know what its subclasses are.

--
Regards,
Charles Bailey  < bailey _at_ newman _dot_ upenn _dot_ edu >
Newman Center at the University of Pennsylvania

(message missing)

Re: A trigger called when following a 'has_a'
Peter Pimley 14:17 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Charles Bailey 14:42 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Peter Pimley 14:53 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Charles Bailey 15:22 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Charles Bailey 15:30 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Peter Pimley 15:37 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Charles Bailey 15:47 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Peter Pimley 10:32 on 21 Jul 2004

A trigger called when following a 'has_a' (again)
Peter Pimley 13:41 on 22 Jul 2004

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