[Catalyst] Explanation of Catalyst::(Helper)::Model::DBIC::Schema

Vsevolod (Simon) Ilyushchenko simonf at cshl.edu
Tue Apr 25 14:29:14 CEST 2006


Tobias,

I was also confused by this, but worked this out with Brandon's help. 
Check out the sample application in t/lib here:
http://www.simonf.com/catalyst/Catalyst-Plugin-MoreFewer-0.01.tar.gz

to see Schemas working under Catalyst.

Simon

Tobias wrote on 04/25/2006 06:00 AM:
> Ok, I admit it: I just don't get how the recommended
> Catalyst::Model::DBIC::Schema and its helper modules should be used!
> 
> I set up some modules and scripts to try out the schema-based approach
> without catalyst and everything worked fine. Here's what I did:
> 
> ---
> 
> package MySchema;
> use base qw/DBIx::Class::Schema/;
> __PACKAGE__->load_classes( qw/Users/ );
> 1;
> 
> package MySchema::Users;
> use base qw/DBIx::Class/;
> __PACKAGE__->load_components( qw/PK::Auto Core/ );
> __PACKAGE__->table( 'users' );
> __PACKAGE__->add_columns( qw/id username password .../ );
> __PACKAGE__->set_primary_key( 'id' );
> 1;
> 
> use MySchema;
> my $schema = MySchema->connect( '...', '...', '...', { AutoCommit => 1 } );
> my $resultset = $schema->resultset( 'Users' )->search( username => 'peter' );
> while( my $user = $resultset->next ) {
>   print $user->username."\n";
> }
> 
> ---
> 
> Works like a charm! Now can please somebody tell me how to use the helper
> scripts to create something similar which is usable inside Catalyst? The
> manpage of Catalyst::Helper::Model::DBIC::Schema says:
> 
> script/myapp_create.pl model Foo DBIC::Schema FooSchema dbi:mysql:foodb myuname
> mypass '{ AutoCommit => 1 }'
> 
> What does "Foo" mean? Where's the difference between "Foo" and "FooSchema"?
> Maybe the wording is a bit misleading here... How do I create the
> Schema-Baseclass (MySchema) and the actual models for the tables
> (MySchema::Users). Unfortunately catalystframework.org is currently
> unavailable.
> 
> Thanx for your help!
> 
> Toby
> 
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
> 

-- 

Simon (Vsevolod ILyushchenko)   simonf at cshl.edu
				http://www.simonf.com

"Think like a man of action, act like a man of thought."

		         Henri Bergson



More information about the Catalyst mailing list