[Catalyst] Adding relationships to loaded CDBI models

Matt S Trout catalyst at trout.me.uk
Thu Jun 16 19:57:38 CEST 2005


On Thu, Jun 16, 2005 at 01:15:52PM -0400, Christopher Heschong wrote:
> So a model based on Catalyst::Model::CDBI loads up all my tables and
> columns, sweet.
> 
> But then how do I extend one of those auto-generated classes with extra
> relationships.
> 
> For instance, in my MyApp::M::CDBI I would like to do this:
> 
> 
> package MyApp::M::CDBI;
> use base 'Catalyst::Model::CDBI';
> __PACKAGE__->config( ... );

sub new {
  my ( $self, $c ) = @_;
  $self = $self->NEXT::new( $c );
 
> MyApp::M::CDBI::Table->has_a (
> 	date	=> 'Class::Date',
> 	inflate	=> 'new',
> 	deflate	=> 'epoch'
> );

  return $self;
}

> 1;
> 
> 
> But at the time that MyApp::M::CDBI is loaded, the MyApp::M::CDBI::Table
> class doesn't exist yet.  I could use Catalyst::Model::CDBI::Plain and
> define everything myself, but is there any way to take the ease of
> C::M::CDBI and extend it a little?

Have a play with the above. I don't use Loader myself so I make no guarantees,
but I suspect that or something close to it will work.

-- 
     Matt S Trout           Website: http://www.shadowcatsystems.co.uk
  Technical Director        E-mail:  mst (at) shadowcatsystems.co.uk
Shadowcat Systems Ltd.



More information about the Catalyst mailing list