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 [ [ 'me.rank' => 13 ], [ 'me.rank' => 13 ] ],
48 'correct SQL on limited prefetch over search_related ordered by root',
51 # note: we only requested "get all cds of all artists with rank 13 then order
52 # by the artist name and give me the fourth, fifth and sixth", consequently the
53 # cds that belong to the same artist are unordered; fortunately we know that
54 # the first artist have 3 cds and the second and third artist both have only
55 # one, so the first 3 cds belong to the first artist and the fourth and fifth
56 # cds belong to the second and third artist, respectively, and there's no sixth
59 [ $filtered_cd_rs->hri_dump ],
65 'single_track' => undef,
66 'title' => 'Generic Manufactured Singles',
70 'last_updated_at' => undef,
71 'last_updated_on' => undef,
73 'title' => 'Boring Name',
78 'last_updated_at' => undef,
79 'last_updated_on' => undef,
81 'title' => 'Boring Song',
86 'last_updated_at' => undef,
87 'last_updated_on' => undef,
89 'title' => 'No More Ideas',
99 'single_track' => undef,
100 'title' => 'Come Be Depressed With Us',
104 'last_updated_at' => undef,
105 'last_updated_on' => undef,
112 'last_updated_at' => undef,
113 'last_updated_on' => undef,
115 'title' => 'Suicidal',
120 'last_updated_at' => undef,
121 'last_updated_on' => undef,
123 'title' => 'Under The Weather',
130 'Correctly ordered result',