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)
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;
}