From: Peter Rabbitson Date: Sat, 12 Dec 2009 23:17:44 +0000 (+0000) Subject: Real test for search_related and prefetch X-Git-Tag: v0.08116~61^2~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=63e943c2fb6d8d4479fb7d2287dcf4fcad577e99;p=dbsrgits%2FDBIx-Class.git Real test for search_related and prefetch --- diff --git a/t/search/related_strip_prefetch.t b/t/search/related_strip_prefetch.t index 3201a4d..10621ae 100644 --- a/t/search/related_strip_prefetch.t +++ b/t/search/related_strip_prefetch.t @@ -12,21 +12,30 @@ my $schema = DBICTest->init_schema(); my $rs = $schema->resultset('CD')->search ( { 'tracks.id' => { '!=', 666 }}, - { join => 'artist', prefetch => 'tracks' } + { join => 'artist', prefetch => 'tracks', rows => 2 } ); -my $rel_rs = $rs->search_related ('tags'); +my $rel_rs = $rs->search_related ('tags', { 'tags.tag' => { '!=', undef }}, { distinct => 1}); is_same_sql_bind ( $rel_rs->as_query, '( - SELECT tags.tagid, tags.cd, tags.tag - FROM cd me + SELECT tags.tagid, tags.cd, tags.tag + FROM ( + SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track + FROM cd me + JOIN artist artist ON artist.artistid = me.artist + LEFT JOIN track tracks ON tracks.cd = me.cdid + WHERE ( tracks.id != ? ) + LIMIT 2 + ) 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 != ? ) + WHERE ( tags.tag IS NOT NULL ) + GROUP BY tags.tagid, tags.cd, tags.tag )', + [ [ 'tracks.id' => 666 ] ], 'Prefetch spec successfully stripped on search_related' );