X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet.pm;h=dce4ad5d7b38d8d0496f1d548b59413b06ab94dc;hb=6d1bf0a9d5c6d11bd70b7d6938403530faeebc2d;hp=acd228c1109d63437754ceccd7383f1294ab5130;hpb=8fab5eef0c0f7f138fdd5f5f23d8cadd48887ba9;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index acd228c..dce4ad5 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -510,7 +510,28 @@ Deletes the contents of the resultset from its result source. sub delete { my ($self) = @_; - $self->result_source->storage->delete($self->result_source->from, $self->{cond}); + 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') { + $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 %{$_}) { + $key =~ /([^\.]+)$/; + $hash{$1} = $_->{$key}; + }; \%hash; } @{$self->{cond}{-and}} ]; + } else { + foreach my $key (keys %{$self->{cond}}) { + $key =~ /([^\.]+)$/; + $del->{$1} = $self->{cond}{$key}; + } + } + $self->result_source->storage->delete($self->result_source->from, $del); return 1; }