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