[Dbix-class] Cascade deletes
Bill Moseley
moseley at hank.org
Sat Mar 6 01:07:25 GMT 2010
First, is there a way to globally disable cascade deletes? I know I can
add cascade_delete =3D> 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 =3D $schema->resultset( 'Artist' )->create( { name =3D> '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 =3D ? ): '25'
SELECT me.id, me.year, me.name, me.artist FROM cd me WHERE ( me.artist =3D ?
): '25'
DELETE FROM cd WHERE ( id =3D ? ): '54'
Why not just delete from cd where artist =3D 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
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20100305/3b9=
76c75/attachment.htm
More information about the DBIx-Class
mailing list