File: 86might_have.t

package info (click to toggle)
libdbix-class-perl 0.08123-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,520 kB
  • ctags: 1,695
  • sloc: perl: 19,821; sql: 353; makefile: 10
file content (64 lines) | stat: -rw-r--r-- 1,386 bytes parent folder | download | duplicates (2)
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
57
58
59
60
61
62
63
64
use strict;
use warnings;  

use Test::More;
use Test::Warn;
use lib qw(t/lib);
use DBICTest;

my $schema = DBICTest->init_schema();

my $queries;
$schema->storage->debugcb( sub{ $queries++ } );
my $sdebug = $schema->storage->debug;

my $cd = $schema->resultset("CD")->find(1);
$cd->title('test');

# SELECT count
$queries = 0;
$schema->storage->debug(1);

$cd->update;

is($queries, 1, 'liner_notes (might_have) not prefetched - do not load 
liner_notes on update');

$schema->storage->debug($sdebug);


my $cd2 = $schema->resultset("CD")->find(2, {prefetch => 'liner_notes'});
$cd2->title('test2');

# SELECT count
$queries = 0;
$schema->storage->debug(1);

$cd2->update;

is($queries, 1, 'liner_notes (might_have) prefetched - do not load 
liner_notes on update');

warning_like {
  DBICTest::Schema::Bookmark->might_have(
    linky => 'DBICTest::Schema::Link',
    { "foreign.id" => "self.link" },
  );
}
  qr{"might_have/has_one" must not be on columns with is_nullable set to true},
  'might_have should warn if the self.id column is nullable';

{
  local $ENV{DBIC_DONT_VALIDATE_RELS} = 1;
  warning_is { 
    DBICTest::Schema::Bookmark->might_have(
      slinky => 'DBICTest::Schema::Link',
      { "foreign.id" => "self.link" },
    );
  }
  undef,
  'Setting DBIC_DONT_VALIDATE_RELS suppresses nullable relation warnings';
}

$schema->storage->debug($sdebug);
done_testing();