From: Matt S Trout Date: Sat, 18 Mar 2006 18:46:35 +0000 (+0000) Subject: Fix for delete on full-table resultsets X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7ed3d6dc7d83264aa67108ec304985c0116d6009;p=dbsrgits%2FDBIx-Class-Historic.git Fix for delete on full-table resultsets --- diff --git a/Changes b/Changes index e8d7c14..ab6d6fb 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for DBIx::Class 0.05999_04 + - Fix for delete on full-table resultsets - Removed caching on count() and added _count for pager() - ->connection does nothing if ->storage defined and no args (and hence ->connect acts like ->clone under the same conditions) diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 4e5d1ee..da955a4 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -655,26 +655,41 @@ Deletes the contents of the resultset from its result source. sub delete { my ($self) = @_; my $del = {}; - $self->throw_exception("Can't delete on resultset with condition unless hash or array") - unless (ref($self->{cond}) eq 'HASH' || ref($self->{cond}) eq 'ARRAY'); - if (ref $self->{cond} eq 'ARRAY') { + + if (!ref($self->{cond})) { + + # No-op. No condition, we're deleting everything + + } elsif (ref $self->{cond} eq 'ARRAY') { + $del = [ map { my %hash; foreach my $key (keys %{$_}) { $key =~ /([^.]+)$/; $hash{$1} = $_->{$key}; }; \%hash; } @{$self->{cond}} ]; - } elsif ((keys %{$self->{cond}})[0] eq '-and') { - $del->{-and} = [ map { my %hash; - foreach my $key (keys %{$_}) { + + } elsif (ref $self->{cond} eq 'HASH') { + + if ((keys %{$self->{cond}})[0] eq '-and') { + + $del->{-and} = [ map { my %hash; + foreach my $key (keys %{$_}) { + $key =~ /([^.]+)$/; + $hash{$1} = $_->{$key}; + }; \%hash; } @{$self->{cond}{-and}} ]; + + } else { + + foreach my $key (keys %{$self->{cond}}) { $key =~ /([^.]+)$/; - $hash{$1} = $_->{$key}; - }; \%hash; } @{$self->{cond}{-and}} ]; - } else { - foreach my $key (keys %{$self->{cond}}) { - $key =~ /([^.]+)$/; - $del->{$1} = $self->{cond}{$key}; + $del->{$1} = $self->{cond}{$key}; + } } + } else { + $self->throw_exception( + "Can't delete on resultset with condition unless hash or array"); } + $self->result_source->storage->delete($self->result_source->from, $del); return 1; }