From: Brandon L. Black Date: Tue, 7 Feb 2006 14:51:35 +0000 (+0000) Subject: prevent accidental table-wide update/delete on row-object from PK-less table X-Git-Tag: v0.05005~25 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4b12b3c2d1e703c9c0e8a402e899e1ccbd4f4ecb;p=dbsrgits%2FDBIx-Class.git prevent accidental table-wide update/delete on row-object from PK-less table --- diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 4c66600..b79b23b 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -98,8 +98,11 @@ sub update { $self->throw_exception( "Not in database" ) unless $self->in_storage; my %to_update = $self->get_dirty_columns; return $self unless keys %to_update; + my $ident_cond = $self->ident_condition; + $self->throw_exception("Cannot safely update a row in a PK-less table") + if ! keys %$ident_cond; my $rows = $self->result_source->storage->update( - $self->result_source->from, \%to_update, $self->ident_condition); + $self->result_source->from, \%to_update, $ident_cond); if ($rows == 0) { $self->throw_exception( "Can't update ${self}: row not found" ); } elsif ($rows > 1) { @@ -123,8 +126,11 @@ sub delete { my $self = shift; if (ref $self) { $self->throw_exception( "Not in database" ) unless $self->in_storage; + my $ident_cond = $self->ident_condition; + $self->throw_exception("Cannot safely delete a row in a PK-less table") + if ! keys %$ident_cond; $self->result_source->storage->delete( - $self->result_source->from, $self->ident_condition); + $self->result_source->from, $ident_cond); $self->in_storage(undef); } else { $self->throw_exception("Can't do class delete without a ResultSource instance")