# appropriately, returning the new condition.
sub _cond_for_update_delete {
- my ($self) = @_;
+ my ($self, $full_cond) = @_;
my $cond = {};
+ $full_cond ||= $self->{cond};
# No-op. No condition, we're updating/deleting everything
- return $cond unless ref $self->{cond};
+ return $cond unless ref $full_cond;
- if (ref $self->{cond} eq 'ARRAY') {
+ if (ref $full_cond eq 'ARRAY') {
$cond = [
map {
my %hash;
$hash{$1} = $_->{$key};
}
\%hash;
- } @{$self->{cond}}
+ } @{$full_cond}
];
}
- elsif (ref $self->{cond} eq 'HASH') {
- if ((keys %{$self->{cond}})[0] eq '-and') {
+ elsif (ref $full_cond eq 'HASH') {
+ if ((keys %{$full_cond})[0] eq '-and') {
$cond->{-and} = [];
- my @cond = @{$self->{cond}{-and}};
+ my @cond = @{$full_cond->{-and}};
for (my $i = 0; $i < @cond; $i++) {
my $entry = $cond[$i];
- my %hash;
+ my $hash;
if (ref $entry eq 'HASH') {
- foreach my $key (keys %{$entry}) {
- $key =~ /([^.]+)$/;
- $hash{$1} = $entry->{$key};
- }
+ $hash = $self->_cond_for_update_delete($entry);
}
else {
$entry =~ /([^.]+)$/;
- $hash{$1} = $cond[++$i];
+ $hash->{$1} = $cond[++$i];
}
- push @{$cond->{-and}}, \%hash;
+ push @{$cond->{-and}}, $hash;
}
}
else {
- foreach my $key (keys %{$self->{cond}}) {
+ foreach my $key (keys %{$full_cond}) {
$key =~ /([^.]+)$/;
- $cond->{$1} = $self->{cond}{$key};
+ $cond->{$1} = $full_cond->{$key};
}
}
}
use DBICTest;\r
my $schema = DBICTest->init_schema();\r
\r
-plan tests => 14;\r
+plan tests => 16;\r
\r
# select from a class with resultset_attributes\r
my $resultset = $schema->resultset('BooksInLibrary');\r
ok(!$@, 'find_or_create on resultset with attribute for non-existent entry did not throw');\r
ok(defined $see_spot, 'successfully did insert on resultset with attribute for non-existent entry');\r
\r
+my $see_spot_rs = $owner->books->search({ title => "See Spot Run" });\r
+eval { $see_spot_rs->delete(); };\r
+if ($@) { print $@ }\r
+ok(!$@, 'delete on resultset with attribute did not throw');\r
+is($see_spot_rs->count(), 0, 'delete on resultset with attributes succeeded');\r
+\r
# many_to_many tests\r
my $collection = $schema->resultset('Collection')->search({collectionid => 1});\r
my $pointy_objects = $collection->search_related('collection_object')->search_related('object', { type => "pointy"});\r