From: Nigel Metheringham Date: Fri, 7 May 2010 13:03:00 +0000 (+0000) Subject: empty update OK even if row is not in database X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=de5ce4818508f52aa7489847319de5bab0ff4454;p=dbsrgits%2FDBIx-Class-Historic.git empty update OK even if row is not in database --- diff --git a/Changes b/Changes index cb90856..f1e998a 100644 --- a/Changes +++ b/Changes @@ -20,6 +20,9 @@ Revision history for DBIx::Class - Fix as_subselect_rs to not inject resultset class-wide where conditions outside of the resulting subquery - Depend on optimized SQL::Abstract (faster SQL generation) + - update on row not in database now OK if no changes - + fixes problems with cascaded unnecessary updates + 0.08121 2010-04-11 18:43:00 (UTC) - Support for Firebird RDBMS with DBD::InterBase and ODBC diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 06f850b..ecbff0c 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -518,7 +518,6 @@ this method. sub update { my ($self, $upd) = @_; - $self->throw_exception( "Not in database" ) unless $self->in_storage; my $ident_cond = $self->{_orig_ident} || $self->ident_condition; @@ -528,6 +527,9 @@ sub update { $self->set_inflated_columns($upd) if $upd; my %to_update = $self->get_dirty_columns; return $self unless keys %to_update; + + $self->throw_exception( "Not in database" ) unless $self->in_storage; + my $rows = $self->result_source->storage->update( $self->result_source, \%to_update, $ident_cond ); diff --git a/t/60core.t b/t/60core.t index 69d99ed..41adcb2 100644 --- a/t/60core.t +++ b/t/60core.t @@ -45,6 +45,8 @@ my %fake_dirty = $art->get_dirty_columns(); is(scalar(keys(%fake_dirty)), 1, '1 fake dirty column'); ok(grep($_ eq 'name', keys(%fake_dirty)), 'name is fake dirty'); +ok($art->update, 'Update run'); + my $record_jp = $schema->resultset("Artist")->search(undef, { join => 'cds' })->search(undef, { prefetch => 'cds' })->next; ok($record_jp, "prefetch on same rel okay"); @@ -67,6 +69,8 @@ is(@art, 2, 'And then there were two'); is($art->in_storage, 0, "It knows it's dead"); +lives_ok { $art->update } 'No changes so update should be OK'; + dies_ok ( sub { $art->delete }, "Can't delete twice"); is($art->name, 'We Are In Rehab', 'But the object is still live');