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: [EMAIL PROTECTED]";
}

...
#--- 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

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]

Reply via email to