File: group_by_func.t

package info (click to toggle)
libdbix-class-perl 0.082844-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,320 kB
  • sloc: perl: 27,215; sql: 322; sh: 29; makefile: 16
file content (36 lines) | stat: -rw-r--r-- 709 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use strict;
use warnings;

use Test::More;

use lib qw(t/lib);

use DBICTest;

my $schema = DBICTest->init_schema();

my $rs = $schema->resultset ('CD')->search ({}, {
  select => [
    { substr => [ 'title', 1, 1 ], -as => 'initial' },
    { count => '*' },
  ],
  as => [qw/title_initial cnt/],
  group_by => ['initial'],
  order_by => { -desc => 'initial' },
  result_class => 'DBIx::Class::ResultClass::HashRefInflator',
});

is_deeply (
  [$rs->all],
  [
    { title_initial => 'S', cnt => '1' },
    { title_initial => 'G', cnt => '1' },
    { title_initial => 'F', cnt => '1' },
    { title_initial => 'C', cnt => '2' },
  ],
  'Correct result',
);

is ($rs->count, 4, 'Correct count');

done_testing;