X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FPK.pm;h=e281dd48ab3c51bfd8f010e9747e3b5b69bf6baf;hb=f71a92ae456d56097108cf2577d4079bb4a48793;hp=bb820e2a2d898e86fa4ec347db20170fa232d331;hpb=ed213e857791d1cfb0f1a0e32674e81358e19564;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/PK.pm b/lib/DBIx/Class/PK.pm index bb820e2..e281dd4 100644 --- a/lib/DBIx/Class/PK.pm +++ b/lib/DBIx/Class/PK.pm @@ -37,8 +37,22 @@ changes made since the row was last read from storage. sub discard_changes { my ($self) = @_; - my $storage = $self->result_source->schema->storage; - $storage->reload_row($self); + delete $self->{_dirty_columns}; + return unless $self->in_storage; # Don't reload if we aren't real! + + my $reload = $self->result_source->schema->storage->reload_row($self); + + unless ($reload) { # If we got deleted in the mean-time + $self->in_storage(0); + return $self; + } + + %$self = %$reload; + + # Avoid a possible infinite loop with + # sub DESTROY { $_[0]->discard_changes } + bless $reload, 'Do::Not::Exist'; + return $self; }