[Dbix-class] bug in delete_all: CascadeActions::delete removes parent before children

Matt S Trout dbix-class at trout.me.uk
Mon Oct 27 23:45:03 GMT 2008


On Fri, Oct 24, 2008 at 02:26:35PM -0700, Noel Burton-Krahn wrote:
> DBIx's cascading delete_all (in DBIx::Class::ResultSet) it broken,
> because it deletes the parent table before it deletes the children.
> The database will throw a referential integrity exception when the
> parent is deleted before the children.

This is intentional behaviour - it produces cascade deletion under MyISAM
and SQLite where the database doesn't provide it, without affecting the
relational integrity of databases that have it.

You need to either (a) set ON CASCADE DELETE in the database or (b) add
an explicit override in your row class such as:

sub delete {
  my $self = shift;
  $self->related_things->delete;
  $self->next::method(@_);
}

A documentation patch to make this more clear would be very welcome.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list