7 use DBIC::SqlMakerTest;
9 use DBIx::Class::SQLMaker::LimitDialects;
11 my ($ROWS, $OFFSET) = (
12 DBIx::Class::SQLMaker::LimitDialects->__rows_bindtype,
13 DBIx::Class::SQLMaker::LimitDialects->__offset_bindtype,
16 my $schema = DBICTest->init_schema();
18 my $artist_rs = $schema->resultset('Artist');
19 my $ar = $artist_rs->current_source_alias;
21 my $filtered_cd_rs = $artist_rs->search_related('cds_unordered',
24 prefetch => [ 'tracks' ],
25 order_by => [ { -asc => "$ar.name" }, "$ar.artistid DESC" ],
32 $filtered_cd_rs->as_query,
34 SELECT cds_unordered.cdid, cds_unordered.artist, cds_unordered.title, cds_unordered.year, cds_unordered.genreid, cds_unordered.single_track,
35 tracks.trackid, tracks.cd, tracks.position, tracks.title, tracks.last_updated_on, tracks.last_updated_at
38 SELECT cds_unordered.cdid, cds_unordered.artist, cds_unordered.title, cds_unordered.year, cds_unordered.genreid, cds_unordered.single_track
41 ON cds_unordered.artist = me.artistid
43 ORDER BY me.name ASC, me.artistid DESC
47 ON cds_unordered.artist = me.artistid
48 LEFT JOIN track tracks
49 ON tracks.cd = cds_unordered.cdid
51 ORDER BY me.name ASC, me.artistid DESC, tracks.cd
54 [ { sqlt_datatype => 'integer', dbic_colname => 'me.rank' } => 13 ],
57 [ { sqlt_datatype => 'integer', dbic_colname => 'me.rank' } => 13 ],
59 'correct SQL on limited prefetch over search_related ordered by root',
62 # note: we only requested "get all cds of all artists with rank 13 then order
63 # by the artist name and give me the fourth, fifth and sixth", consequently the
64 # cds that belong to the same artist are unordered; fortunately we know that
65 # the first artist have 3 cds and the second and third artist both have only
66 # one, so the first 3 cds belong to the first artist and the fourth and fifth
67 # cds belong to the second and third artist, respectively, and there's no sixth
70 $filtered_cd_rs->all_hri,
76 'single_track' => undef,
77 'title' => 'Generic Manufactured Singles',
81 'last_updated_at' => undef,
82 'last_updated_on' => undef,
84 'title' => 'Boring Name',
89 'last_updated_at' => undef,
90 'last_updated_on' => undef,
92 'title' => 'Boring Song',
97 'last_updated_at' => undef,
98 'last_updated_on' => undef,
100 'title' => 'No More Ideas',
110 'single_track' => undef,
111 'title' => 'Come Be Depressed With Us',
115 'last_updated_at' => undef,
116 'last_updated_on' => undef,
123 'last_updated_at' => undef,
124 'last_updated_on' => undef,
126 'title' => 'Suicidal',
131 'last_updated_at' => undef,
132 'last_updated_on' => undef,
134 'title' => 'Under The Weather',
141 'Correctly ordered result',