From: Matt S Trout Date: Mon, 6 Feb 2006 18:15:44 +0000 (+0000) Subject: Fix up delete code after previous commit X-Git-Tag: v0.05005~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ca4b5ab70c1f6979600c72a7a3ef4f74f5f28f5f;p=dbsrgits%2FDBIx-Class.git Fix up delete code after previous commit --- diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index e3f4258..b10c687 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -99,9 +99,20 @@ sub search_related { my $query = ((@_ > 1) ? {@_} : shift); my ($cond) = $self->result_source->resolve_condition($rel_obj->{cond}, $rel, $self); - foreach my $key (keys %$cond) { - unless ($key =~ m/\./) { - $cond->{"me.$key"} = delete $cond->{$key}; + if (ref $cond eq 'ARRAY') { + $cond = [ map { my %hash; + foreach my $key (keys %{$_}) { + unless ($key =~ m/\./) { + $hash{"me.$key"} = $_->{$key}; + } else { + $hash{$key} = $_->{$key}; + } + }; \%hash; } @$cond ]; + } else { + foreach my $key (keys %$cond) { + unless ($key =~ m/\./) { + $cond->{"me.$key"} = delete $cond->{$key}; + } } } $query = ($query ? { '-and' => [ $cond, $query ] } : $cond); 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; }