First, is there a way to globally disable cascade deletes? I know I can
add cascade_delete => 0 to the relationships, but I never want cascade
deletes in the ORM (I have a database that does that).
Second,
Say I have my music db and an error in a relationship name. Then I do this:
my $artist = $schema->resultset( 'Artist' )->create( { name => 'test
aritst' } );
$artist->delete;
I get this exception on the delete call:
DBIx::Class::Relationship::CascadeActions::delete(): Can't find source for
MyApp::Result::Cdxx at /home/moseley/dbic_music/test.pl line 19
So, the Cdxx class didn't get loaded until trying to do the cascade delete.
I guess that's ok. But what I find awkward is that $artist->delete threw
an exception but still deleted the artist row. If $artist->delete is
multiple database calls behind the scene shouldn't they be wrapped in a
transaction?
Or is it expected that deletes are explicitly placed in a transaction?
$schema->txn_do( sub { $artist->delete } );
I notice that DBIC does a select to find the related rows (i.e. in the Cd
table when looking for rows to cascade delete). Is there a reason that's
done instead of just deleting directly?
INSERT INTO artist ( label, name) VALUES ( ?, ? ): '1', 'test aritst'
INSERT INTO cd ( artist) VALUES ( ? ): '25'
DELETE FROM artist WHERE ( id = ? ): '25'
SELECT me.id, me.year, me.name, me.artist FROM cd me WHERE ( me.artist = ?
): '25'
DELETE FROM cd WHERE ( id = ? ): '54'
Why not just delete from cd where artist = 25?
Again, sure seems like that should be inside a transaction.
Notes about cascade deletes:
http://search.cpan.org/~ribasushi/DBIx-Class-0.08120/lib/DBIx/Class/Row.pm#delete
--
Bill Moseley
[email protected]
_______________________________________________
List: http://lists.scsys.co.uk/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]