From: David Kamholz Date: Wed, 22 Nov 2006 20:12:43 +0000 (+0000) Subject: re-commit minimal pk-mutation in update(), with test X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5a9e0e60ac1a8f30b6e7663c6a7315998c4d5e9a;p=dbsrgits%2FDBIx-Class-Historic.git re-commit minimal pk-mutation in update(), with test --- diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 57f883f..213f3cc 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -110,12 +110,12 @@ required. sub update { my ($self, $upd) = @_; $self->throw_exception( "Not in database" ) unless $self->in_storage; - $self->set_columns($upd) if $upd; - 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; + $self->set_columns($upd) if $upd; + my %to_update = $self->get_dirty_columns; + return $self unless keys %to_update; my $rows = $self->result_source->storage->update( $self->result_source->from, \%to_update, $ident_cond); if ($rows == 0) { diff --git a/t/69update.t b/t/69update.t index 3372b4f..b11ebde 100644 --- a/t/69update.t +++ b/t/69update.t @@ -9,7 +9,7 @@ my $schema = DBICTest->init_schema(); BEGIN { eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 3); + plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 5); } my $art = $schema->resultset("Artist")->find(1); @@ -27,3 +27,6 @@ ok($art->name($name) eq $name, 'update'); $art->discard_changes; +ok($art->update({ artistid => 100 }), 'update allows pk mutation'); + +is($art->artistid, 100, 'pk mutation applied');