Retire DBIC/SqlMakerTest.pm now that SQLA::Test provides the same function
[dbsrgits/DBIx-Class.git] / t / search / related_strip_prefetch.t
CommitLineData
47c10423 1use strict;
2use warnings;
3
4use Test::More;
47c10423 5
6use lib qw(t/lib);
a5a7bb73 7use DBICTest ':DiffSQL';
fcb7fcbb 8use DBIx::Class::SQLMaker::LimitDialects;
9
10my $ROWS = DBIx::Class::SQLMaker::LimitDialects->__rows_bindtype;
47c10423 11
12my $schema = DBICTest->init_schema();
13
14my $rs = $schema->resultset('CD')->search (
0e773352 15 { 'tracks.trackid' => { '!=', 666 }},
63e943c2 16 { join => 'artist', prefetch => 'tracks', rows => 2 }
47c10423 17);
18
63e943c2 19my $rel_rs = $rs->search_related ('tags', { 'tags.tag' => { '!=', undef }}, { distinct => 1});
47c10423 20
21is_same_sql_bind (
22 $rel_rs->as_query,
23 '(
63e943c2 24 SELECT tags.tagid, tags.cd, tags.tag
25 FROM (
26 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
27 FROM cd me
28 JOIN artist artist ON artist.artistid = me.artist
fcb7fcbb 29 LEFT JOIN track tracks ON tracks.cd = me.cdid
0e773352 30 WHERE ( tracks.trackid != ? )
fcb7fcbb 31 LIMIT ?
63e943c2 32 ) me
47c10423 33 JOIN artist artist ON artist.artistid = me.artist
8baabfd8 34 JOIN tags tags ON tags.cd = me.cdid
63e943c2 35 WHERE ( tags.tag IS NOT NULL )
36 GROUP BY tags.tagid, tags.cd, tags.tag
47c10423 37 )',
63e943c2 38
fcb7fcbb 39 [
40 [ { sqlt_datatype => 'integer', dbic_colname => 'tracks.trackid' } => 666 ],
41 [ $ROWS => 2 ]
0e773352 42 ],
47c10423 43 'Prefetch spec successfully stripped on search_related'
44);
45
46done_testing;