#
# update/delete require the condition to be modified to handle
# the differing SQL syntax available. This transforms the $self->{cond}
-# appropriately, returning the new condition
+# appropriately, returning the new condition.
sub _cond_for_update_delete {
my ($self) = @_;
my $cond = {};
if (!ref($self->{cond})) {
- # No-op. No condition, we're update/deleting everything
+ # No-op. No condition, we're updating/deleting everything
}
elsif (ref $self->{cond} eq 'ARRAY') {
$cond = [
$hash{$1} = $_->{$key};
}
\%hash;
- } @{$self->{cond}}
+ } @{$self->{cond}}
];
}
elsif (ref $self->{cond} eq 'HASH') {
if ((keys %{$self->{cond}})[0] eq '-and') {
- $cond->{-and} = [
- map {
- my %hash;
- foreach my $key (keys %{$_}) {
+ $cond->{-and} = [];
+
+ my @cond = @{$self->{cond}{-and}};
+ for (my $i = 0; $i < @cond - 1; $i++) {
+ my $entry = $cond[$i];
+
+ my %hash;
+ if (ref $entry eq 'HASH') {
+ foreach my $key (keys %{$entry}) {
$key =~ /([^.]+)$/;
- $hash{$1} = $_->{$key};
+ $hash{$1} = $entry->{$key};
}
- \%hash;
- } @{$self->{cond}{-and}}
- ];
+ }
+ else {
+ $entry =~ /([^.]+)$/;
+ $hash{$entry} = $cond[++$i];
+ }
+
+ push @{$cond->{-and}}, \%hash;
+ }
}
else {
foreach my $key (keys %{$self->{cond}}) {
}
else {
$self->throw_exception(
- "Can't update/delete on resultset with condition unless hash or array");
+ "Can't update/delete on resultset with condition unless hash or array"
+ );
}
+
return $cond;
}