[Catalyst] Catalyst Digest, Vol 15, Issue 38

dennis ddaupert at sbcglobal.net
Tue May 16 18:45:19 CEST 2006


On Tuesday 16 May 2006 06:00, catalyst-request at lists.rawmode.org wrote:
> > #------------------------------------
> > Create the DBIx:Class schema
> > #------------------------------------
> > package Catapult::Schema::CatapultDB;
> >
> > use warnings;
> > use strict;
> > use base qw/DBIx::Class::Schema/;
> >
> > __PACKAGE__->load_classes(qw/Quotes/);
> >
> > 1;
> > #------------------------------------
> > Create a class for the table in the database
> > #------------------------------------
> > package Catapult::Schema::CatapultDB::Quotes;
> >
> > use base qw/DBIx::Class/;
> >
> > __PACKAGE__->load_components(qw/ PK::Auto::Pg Core /);
> > # Set the table name
> > __PACKAGE__->table('quotes');
> > # Set columns in table
> > __PACKAGE__->add_columns(qw/id quote author/);
> > # Set the primary key for the table
> > __PACKAGE__->set_primary_key(qw/id/);
> >
> > 1;
> > #------------------------------------
> > To expose it to Catalyst as a model...
> > #------------------------------------
> > package Catapult::Model::CatapultDB;
> >
> > use warnings;
> > use strict;
> >
> > use base qw/Catalyst::Model::DBIC::Schema/;
> >
> > __PACKAGE__->config (
> >     schema_class => 'Catapult::Schema::CatapultDB',
> >     connect_info => [
> >                      'dbi::Pg:dbname=catapult',
> >                      'catapult',
> >                      '',
> >                     {
> >                      RaiseError => 1,
> >                      PrintError => 0,
> >                      ShowErrorStatement => 1,
> >                      Tracelevel => 0,
> >                     }]);
> >
> > 1;
> > #------------------------------------
> > Now in my controller:
> > #------------------------------------
> > sub list : Path('/text/quote/list_quote') {
> >   my ($self, $c) = @_;
> >
> >   $c->stash->{quotes} = [$c->model('Quotes')->all];
> >   $c->stash->{template} = 'text/quote/list_quote.tt';
> > }
> > #------------------------------------
> >
> > I know my DB is setup correctly, my previous code based on Kennedy's auth
> > tutorial did at least retrieve the list of quotes in the quotes table.
> >
> > Any thoughts?
>
> $c->model('CatapultDB::Quotes')
>
> just like I already said in my last reply to this thread.

Yes, I saw that, but my code base has changed quite a bit since I tried to 
conform my code to the documentation for Catalyst::Model::DBIC::Schema.
I had actually tried $c->model('CatapultDB::Quotes') with current code, but 
still get problem. Debug output shows "GET" request for 
"text/quote/list_quote", followed by Rendering template "page/index.tt"


One thing I'm still puzzling over, is does the DBIx majick perform the db 
connection after setting up the connect_info bits, or do I have to do that 
explicitly? And if so, how do I do that? Several attempts failed, so if 
that's my problem I need a bit of format assistance.

> Also note that on any recent DBIx::Class you only need to specify
> PK::Auto - it'll automatically select the Pg implementation for you.

Ah, thanks, I'll change that as well. 

/dennis




More information about the Catalyst mailing list