Skip to content

Commit

Permalink
Fix up delete code after previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowcat-mst committed Feb 6, 2006
1 parent 8fab5ee commit ca4b5ab
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
17 changes: 14 additions & 3 deletions lib/DBIx/Class/Relationship/Base.pm
Expand Up @@ -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);
Expand Down
23 changes: 22 additions & 1 deletion lib/DBIx/Class/ResultSet.pm
Expand Up @@ -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;
}

Expand Down

0 comments on commit ca4b5ab

Please sign in to comment.