WIP recursing order_by madness so far (hard because of an API hole - what is a column...
[dbsrgits/DBIx-Class.git] / t / sqlahacks / order_by_func.t
CommitLineData
5e120ab6 1use strict;
2use warnings;
3use Test::More;
4
5use lib qw(t/lib);
6use DBICTest;
7use DBIC::SqlMakerTest;
8
9my $schema = DBICTest->init_schema();
adb51ba4 10$schema->storage->sql_maker->quote_char ('"');
11$schema->storage->sql_maker->name_sep ('.');
5e120ab6 12
13my $rs = $schema->resultset('CD')->search({}, {
14 'join' => 'tracks',
adb51ba4 15 order_by => [
16 { -length => 'me.title' },
17 {
5e120ab6 18 -desc => {
adb51ba4 19 count => 'tracks.trackid',
5e120ab6 20 },
adb51ba4 21 },
22 ],
5e120ab6 23 distinct => 1,
24 rows => 2,
adb51ba4 25 page => 2,
5e120ab6 26});
5e120ab6 27
adb51ba4 28is_same_sql_bind(
29 $rs->as_query,
30 '(
31 SELECT "me"."cdid", "me"."artist", "me"."title", "me"."year", "me"."genreid", "me"."single_track"
32 FROM cd "me"
33 LEFT JOIN "track" "tracks" ON "tracks"."cd" = "me"."cdid"
34 GROUP BY "me"."cdid", "me"."artist", "me"."title", "me"."year", "me"."genreid", "me"."single_track"
35 ORDER BY
36 LENGTH( "me"."title" ),
37 COUNT( "tracks"."trackid" ) DESC
38 LIMIT 2 OFFSET 2
39 )',
40 [],
41 'order by with func query',
42);
5e120ab6 43
adb51ba4 44ok($rs->count_rs->next == 2, 'amount of rows return in order by func query');
45is_deeply (
46 [ $rs->get_column ('me.title')->all ],
47 [ "Caterwaulin' Blues", "Come Be Depressed With Us" ],
48 'Correctly ordered stuff by title-length',
49);
5e120ab6 50
51done_testing;