From: Peter Rabbitson Date: Thu, 4 Feb 2010 10:28:33 +0000 (+0000) Subject: Fix bug reported by tommyt X-Git-Tag: v0.08116~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=037e8dca0dd1700345e2a36f78b399b59b8de99a;p=dbsrgits%2FDBIx-Class.git Fix bug reported by tommyt --- diff --git a/Changes b/Changes index a5e5560..6b6b893 100644 --- a/Changes +++ b/Changes @@ -19,6 +19,8 @@ Revision history for DBIx::Class overloads - Fix ResultSetColumn improperly selecting more than the requested column when +columns/+select is present + - Fix failure when update/delete of resultsets with complex WHERE + SQLA structures - Fix regression in context sensitiveness of deployment_statements - Fix regression resulting in overcomplicated query on search_related from prefetching resultsets diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index dd53655..331474f 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -459,13 +459,17 @@ sub _strip_cond_qualifiers { for (my $i = 0; $i < @cond; $i++) { my $entry = $cond[$i]; my $hash; - if (ref $entry eq 'HASH') { + my $ref = ref $entry; + if ($ref eq 'HASH' or $ref eq 'ARRAY') { $hash = $self->_strip_cond_qualifiers($entry); } - else { + elsif (! $ref) { $entry =~ /([^.]+)$/; $hash->{$1} = $cond[++$i]; } + else { + $self->throw_exception ("_strip_cond_qualifiers() is unable to handle a condition reftype $ref"); + } push @{$cond->{-and}}, $hash; } } diff --git a/t/delete/complex.t b/t/delete/complex.t new file mode 100644 index 0000000..5057391 --- /dev/null +++ b/t/delete/complex.t @@ -0,0 +1,35 @@ +use strict; +use warnings; + +use Test::More; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); +my $artist_rs = $schema->resultset ('Artist'); + +my $init_count = $artist_rs->count; +ok ($init_count, 'Some artists is database'); + +$artist_rs->populate ([ + { + name => 'foo', + }, + { + name => 'bar', + } +]); + +is ($artist_rs->count, $init_count + 2, '2 Artists created'); + +$artist_rs->search ({ + -and => [ + { 'me.artistid' => { '!=', undef } }, + [ { 'me.name' => 'foo' }, { 'me.name' => 'bar' } ], + ], +})->delete; + +is ($artist_rs->count, $init_count, 'Correct amount of artists deleted'); + +done_testing; +