From: Peter Rabbitson Date: Sat, 12 Dec 2009 23:07:00 +0000 (+0000) Subject: Extra test to highlight search_related inefficiency X-Git-Tag: v0.08116~61^2~25 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=47c1042322712fc11bc709ff701e2292a39aedde;p=dbsrgits%2FDBIx-Class.git Extra test to highlight search_related inefficiency --- diff --git a/t/search/related_strip_prefetch.t b/t/search/related_strip_prefetch.t new file mode 100644 index 0000000..3201a4d --- /dev/null +++ b/t/search/related_strip_prefetch.t @@ -0,0 +1,34 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; + +use lib qw(t/lib); +use DBIC::SqlMakerTest; +use DBICTest; + +my $schema = DBICTest->init_schema(); + +my $rs = $schema->resultset('CD')->search ( + { 'tracks.id' => { '!=', 666 }}, + { join => 'artist', prefetch => 'tracks' } +); + +my $rel_rs = $rs->search_related ('tags'); + +is_same_sql_bind ( + $rel_rs->as_query, + '( + SELECT tags.tagid, tags.cd, tags.tag + FROM cd me + JOIN artist artist ON artist.artistid = me.artist + LEFT JOIN track tracks ON tracks.cd = me.cdid + LEFT JOIN tags tags ON tags.cd = me.cdid + WHERE ( tracks.id != ? ) + )', + [ [ 'tracks.id' => 666 ] ], + 'Prefetch spec successfully stripped on search_related' +); + +done_testing;