[Dbix-class] Exception not thrown when using create
whatchyatalkinboutwillis at comcast.net
whatchyatalkinboutwillis at comcast.net
Tue Aug 14 16:59:10 GMT 2007
Hello,
I am a newbie to DBIx::Class, however, I am noticing that an exception is not
being thrown when an error occurs when using create to insert a new row and
related rows into the database. I did notice that an exception does get thrown
when create is not used to create related rows (in the sample code below, this
is the equivalent of removing the 'prices' key from the product hash reference).
When an error does occur, a rollback does get issued, however I am just not sure
why no exception gets thrown. Is this by design? Is it not appropriate to use
create to create related rows?
#--- Sample Code ---#
...
my $schema = MyDB::Schema->connect('dbi:Oracle:' ,$dsn,'',{AutoCommit=>1});
my $product = { isbn => '9780123456786',
title => 'Sample Title',
prices => [ { price_amount => 10.95, rc_currency_code => 'USD',
rc_price_type_code => 'NET' } ]
};
my $rs;
my $coderef = sub { $schema->resultset('Products')->create($product); };
eval {
$rs = $schema->txn_do( $coderef );
};
if ($@) {
print "Exception: $@\n";
}
...
#--- End Sample Code ---#
In MyDB::Schema::Products.pm, I have a has_many relationship defined linking
products to prices:
__PACKAGE__->has_many(
"prices",
"MyDB::Schema::Prices",
{ "foreign.product_id" => "self.product_id" },
);
Thanks for any help or advice that you can give me,
Willis
More information about the DBIx-Class
mailing list