X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fresultset%2Fupdate_delete.t;h=539ae64ed5d5af360a81c57d2ce7e1eae3d579cf;hb=59ac6523753f5ef410732194452fe8a0c4ac99e3;hp=542ea073ce54c2d1377d445a1b749f0cdb1e6707;hpb=fef47a8e19fdafd3f039a6c2494d2e8051b3faef;p=dbsrgits%2FDBIx-Class.git diff --git a/t/resultset/update_delete.t b/t/resultset/update_delete.t index 542ea07..539ae64 100644 --- a/t/resultset/update_delete.t +++ b/t/resultset/update_delete.t @@ -5,6 +5,8 @@ use lib qw(t/lib); use Test::More; use Test::Exception; use DBICTest; +use DBIC::DebugObj; +use DBIC::SqlMakerTest; my $schema = DBICTest->init_schema(); @@ -104,8 +106,28 @@ is_deeply ( 'Only two rows incremented (where => scalarref works)', ); -$sub_rs->delete; +{ + 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'); # make sure limit-only deletion works @@ -113,4 +135,29 @@ cmp_ok ($tkfk_cnt, '>', 1, 'More than 1 row left'); $tkfks->search ({}, { rows => 1 })->delete; is ($tkfks->count, $tkfk_cnt -= 1, 'Only one row deleted'); + +# Make sure prefetch is properly stripped too +# check with sql-equality, as sqlite will accept bad sql just fine +my ($sql, @bind); +my $orig_debugobj = $schema->storage->debugobj; +my $orig_debug = $schema->storage->debug; + +$schema->storage->debugobj (DBIC::DebugObj->new (\$sql, \@bind) ); +$schema->storage->debug (1); +$schema->resultset('CD')->search( + { year => { '!=' => 2010 } }, + { prefetch => 'liner_notes' }, +)->delete; + +$schema->storage->debugobj ($orig_debugobj); +$schema->storage->debug ($orig_debug); + +is_same_sql_bind ( + $sql, + \@bind, + 'DELETE FROM cd WHERE ( cdid IN ( SELECT me.cdid FROM cd me WHERE ( year != ? ) GROUP BY me.cdid ) )', + ["'2010'"], + 'Update on prefetching resultset strips prefetch correctly' +); + done_testing;