From: Aaron Crane Date: Thu, 7 Oct 2010 14:58:33 +0000 (+0100) Subject: Fix bug in update of resultset using qualified condition in "-or" X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=59ac6523753f5ef410732194452fe8a0c4ac99e3;p=dbsrgits%2FDBIx-Class-Historic.git Fix bug in update of resultset using qualified condition in "-or" DBIx::Class::Storage::DBIHacks::_strip_cond_qualifiers was failing to recurse down "-or" conditions. Add minimal support for that, including a test. --- diff --git a/Changes b/Changes index b80fe04..6ddd10a 100644 --- a/Changes +++ b/Changes @@ -30,6 +30,8 @@ Revision history for DBIx::Class due to badly-written handlers (the mechanism was never meant to be able to suppress exceptions) - Fixed rels ending with me breaking subqueried limit realiasing + - Fixed $rs->update/delete on resutsets constrained by an + -or condition - Remove rogue GROUP BY on non-multiplying prefetch-induced subqueries - Oracle sequence detection now *really* works across schemas diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index ba81cc4..ff2dc6c 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -239,6 +239,8 @@ andyg: Andy Grundman ank: Andres Kievsky +arc: Aaron Crane + arcanez: Justin Hunter ash: Ash Berlin diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index 7576eb9..5256700 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -520,8 +520,13 @@ sub _strip_cond_qualifiers { } else { foreach my $key (keys %$where) { - $key =~ /([^.]+)$/; - $cond->{$1} = $where->{$key}; + if ($key eq '-or' && ref $where->{$key} eq 'ARRAY') { + $cond->{$key} = $self->_strip_cond_qualifiers($where->{$key}); + } + else { + $key =~ /([^.]+)$/; + $cond->{$1} = $where->{$key}; + } } } } diff --git a/t/resultset/update_delete.t b/t/resultset/update_delete.t index a016d46..539ae64 100644 --- a/t/resultset/update_delete.t +++ b/t/resultset/update_delete.t @@ -106,6 +106,27 @@ is_deeply ( 'Only two rows incremented (where => scalarref works)', ); +{ + my $rs = $schema->resultset('FourKeys_to_TwoKeys')->search ( + { + -or => [ + { 'me.pilot_sequence' => 12 }, + { 'me.autopilot' => 'b' }, + ], + } + ); + lives_ok { $rs->update({ autopilot => 'z' }) } + 'Update with table name qualifier in -or conditions lives'; + is_deeply ( + [ $tkfks->search ({ pilot_sequence => [12, 22]}) + ->get_column ('autopilot')->all + ], + [qw/z z/], + '... and yields the right data', + ); +} + + $sub_rs->delete; is ($tkfks->count, $tkfk_cnt -= 2, 'Only two rows deleted');