File: correlate-relationship.t

package info (click to toggle)
libdbix-class-helpers-perl 2.013002-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 420 kB
  • sloc: perl: 1,931; sql: 73; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,115 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!perl

use strict;
use warnings;

use lib 't/lib';
use Test::More;
use Test::Deep;

use TestSchema;
my $schema = TestSchema->deploy_or_connect();
$schema->prepopulate;

my $rs = $schema->resultset('Gnarly')->search(undef, {
   '+columns' => {
      old_gnarlies => $schema->resultset('Gnarly')
         ->correlate('gnarly_stations')
         ->search({ station_id => { '>' => 2 }})
         ->count_rs->as_query,
      new_gnarlies => $schema->resultset('Gnarly')
         ->correlate('gnarly_stations')
         ->search({ station_id => { '<=' => 2 }})
         ->count_rs->as_query,
   },
   result_class => '::HRI',
});

cmp_deeply([$rs->all], [
  {
    id => 1,
    literature => undef,
    name => "frew",
    new_gnarlies => 1,
    old_gnarlies => 1,
    your_mom => undef
  },
  {
    id => 2,
    literature => undef,
    name => "frioux",
    new_gnarlies => 1,
    old_gnarlies => 0,
    your_mom => undef
  },
  {
    id => 3,
    literature => undef,
    name => "frooh",
    new_gnarlies => 1,
    old_gnarlies => 0,
    your_mom => undef
  }

], 'relationship correlated correctly');

done_testing;