Commit | Line | Data |
5e120ab6 |
1 | use strict; |
2 | use warnings; |
3 | use Test::More; |
4 | |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | use DBIC::SqlMakerTest; |
8 | |
9 | my $schema = DBICTest->init_schema(); |
ba42e08c |
10 | $schema->storage->sql_maker->quote_char ('"'); |
11 | $schema->storage->sql_maker->name_sep ('.'); |
5e120ab6 |
12 | |
13 | my $rs = $schema->resultset('CD')->search({}, { |
14 | 'join' => 'tracks', |
ba42e08c |
15 | order_by => [ |
16 | { -length => 'me.title' }, |
17 | { |
5e120ab6 |
18 | -desc => { |
ba42e08c |
19 | count => 'tracks.trackid', |
5e120ab6 |
20 | }, |
ba42e08c |
21 | }, |
22 | ], |
5e120ab6 |
23 | distinct => 1, |
24 | rows => 2, |
ba42e08c |
25 | page => 2, |
5e120ab6 |
26 | }); |
5e120ab6 |
27 | |
ba42e08c |
28 | is_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 | |
ba42e08c |
44 | ok($rs->count_rs->next == 2, 'amount of rows return in order by func query'); |
45 | is_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 | |
51 | done_testing; |