[Dbix-class] Order of operations in CascadeActions::delete
Jess Robinson
castaway at desert-island.me.uk
Tue Apr 24 13:44:13 GMT 2007
On Thu, 19 Apr 2007, Pedro Melo wrote:
> Hi,
>
> looking at CascadeActions::delete
> (http://search.cpan.org/src/JROBINSON/DBIx-Class-0.07999_02/lib/DBIx/Class/Relationship/CascadeActions.pm),
> the code deletes $self and then goes on to delete the related objects.
> Shouldn't this be the reverse?
>
> If a database has FOREIGN KEYs statements with ON DELETE CASCADE, the second
> part will never find any elements to delete. Also, even if we don't have ON
> DELETE CASCADE at the database level, it makes more sense to me to first
> delete the related objects and only then delete the "parent" object.
DBIC much prefers that you allow/setup the database to do the
delete-cascading, if it deleted the related objects first, and then the
main one, then DB-side would never kick in. Also if the DB rels had ON
CASCADE FAIL set, we'd never trigger it.
The DBIC-side cascade is merely to paper over the cracks of databases that
don't support DB-side FK setting and so on.
Jess
More information about the Dbix-class
mailing list