[Catalyst] Handling Exceptions

Matt S Trout dbix-class at trout.me.uk
Sun Apr 16 19:15:51 CEST 2006


Kiefer, Sascha wrote:
> Hi.
> 
> First, see what i have:
> 
> package MyApp::Model::DBIC::User;
> 
> use strict;
> use warnings;
> use base 'DBIx::Class::Core';
> 
> __PACKAGE__->has_one ( profile  => 'MyApp::Model::DBIC::UserProfile',
> 'userId' );
> __PACKAGE__->has_one ( settings => 'MyApp::Model::DBIC::UserSettings',
> 'userId' );
> 
> Now i create a user:
> 
> my $user = $c->model('DBIC::User')->create(
> 	{
> 		username => $username,
> 		password => $csh->generate,
> 	}
> );
> my $profile  = $user->create_related( 'profile',  { email => $emailaddr, }
> );
> my $settings = $user->create_related( 'settings', { registerDate =>
> DateTime->now } );
> 
> 
> This is all good, but let's say createing the settings does not work/fails
> for some reason.
> I get a exception. But then i would like to rollback the creating of the
> user and ist profile.
> What's the best practice for that?

perldoc DBIx::Class::Schema and read up on txn_do

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Catalyst mailing list