7 use DBIC::SqlMakerTest;
10 my $schema = DBICTest->init_schema();
12 my $artist_rs = $schema->resultset('Artist');
13 my $ar = $artist_rs->current_source_alias;
15 my $filtered_cd_rs = $artist_rs->search_related('cds_unordered',
18 prefetch => [ 'tracks' ],
19 order_by => [ { -asc => "$ar.name" }, "$ar.artistid DESC" ],
26 $filtered_cd_rs->as_query,
28 SELECT cds_unordered.cdid, cds_unordered.artist, cds_unordered.title, cds_unordered.year, cds_unordered.genreid, cds_unordered.single_track,
29 tracks.trackid, tracks.cd, tracks.position, tracks.title, tracks.last_updated_on, tracks.last_updated_at
32 SELECT cds_unordered.cdid, cds_unordered.artist, cds_unordered.title, cds_unordered.year, cds_unordered.genreid, cds_unordered.single_track
35 ON cds_unordered.artist = me.artistid
37 ORDER BY me.name ASC, me.artistid DESC
41 ON cds_unordered.artist = me.artistid
42 LEFT JOIN track tracks
43 ON tracks.cd = cds_unordered.cdid
45 ORDER BY me.name ASC, me.artistid DESC, tracks.cd
47 [ map { [ { sqlt_datatype => 'integer', dbic_colname => 'me.rank' }
50 'correct SQL on limited prefetch over search_related ordered by root',
53 # note: we only requested "get all cds of all artists with rank 13 then order
54 # by the artist name and give me the fourth, fifth and sixth", consequently the
55 # cds that belong to the same artist are unordered; fortunately we know that
56 # the first artist have 3 cds and the second and third artist both have only
57 # one, so the first 3 cds belong to the first artist and the fourth and fifth
58 # cds belong to the second and third artist, respectively, and there's no sixth
61 [ $filtered_cd_rs->hri_dump ],
67 'single_track' => undef,
68 'title' => 'Generic Manufactured Singles',
72 'last_updated_at' => undef,
73 'last_updated_on' => undef,
75 'title' => 'Boring Name',
80 'last_updated_at' => undef,
81 'last_updated_on' => undef,
83 'title' => 'Boring Song',
88 'last_updated_at' => undef,
89 'last_updated_on' => undef,
91 'title' => 'No More Ideas',
101 'single_track' => undef,
102 'title' => 'Come Be Depressed With Us',
106 'last_updated_at' => undef,
107 'last_updated_on' => undef,
114 'last_updated_at' => undef,
115 'last_updated_on' => undef,
117 'title' => 'Suicidal',
122 'last_updated_at' => undef,
123 'last_updated_on' => undef,
125 'title' => 'Under The Weather',
132 'Correctly ordered result',