[Catalyst] Model/Schema questions

Patryk Dwórznik dwuziu at bzium.net
Sun May 21 18:22:51 CEST 2006


Hi,
I would really appreciate if someone could explain me how to properly  
use a DBIC model in a Catalyst application.

I've got a schema and a model class (this is almost copy&pasted from  
Catalyst manual) with a function doing some transaction in it. What I  
want to do in the following controller is to create a user object  
using the function from MyApp::Model::DB::User. Two problems emerge:
  - how to access model classes from controller?
  - how to get  the schema object in model classes?

Here's the code. I hope I don't misunderstand the whole concept. :-)

package MyApp::Controller::User

sub register {
	my( $self, $c ) = @_;

	my $user_class = $c->model('DB::User'); # this unfortunately  
returns  DBIx::Class::ResultSet
	my $user = $user_class->register(); # want to create an object

}


package MyApp::Model::DB::User;
use base qw/MyApp::Schema::DB::User/;

sub register {
	my( $class ) = @_;

	my $user;
	$schema->txn_do( sub { ... } ); # where to get $schema from?
	return $user;
}


   package MyApp::Schema::DB;
   use base qw/DBIx::Class::Schema/;

   __PACKAGE__->load_classes(qw/User/);


  package MyApp::Schema::DB::User;
use base qw/DBIx::Class/;

__PACKAGE__->load_components(qw/PK::Auto Core/);

...

package MyApp::Model::DB;
   use base qw/Catalyst::Model::DBIC::Schema/;

   __PACKAGE__->config(
       schema_class => 'MyApp::Schema::DB',
       connect_info => [ ... ]
   );




-- 
Patryk Dwórznik


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2361 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060521/35193fb3/attachment.bin 


More information about the Catalyst mailing list