Commit | Line | Data |
70350518 |
1 | use strict; |
8273e845 |
2 | use warnings; |
70350518 |
3 | |
4 | use Test::More; |
dc571b76 |
5 | use Test::Warn; |
70350518 |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | |
a47e1233 |
9 | my $schema = DBICTest->init_schema(); |
8417f5ee |
10 | |
11 | my $queries; |
8417f5ee |
12 | $schema->storage->debugcb( sub{ $queries++ } ); |
a2287768 |
13 | my $sdebug = $schema->storage->debug; |
8417f5ee |
14 | |
8417f5ee |
15 | my $cd = $schema->resultset("CD")->find(1); |
16 | $cd->title('test'); |
17 | |
18 | # SELECT count |
19 | $queries = 0; |
20 | $schema->storage->debug(1); |
21 | |
22 | $cd->update; |
23 | |
8273e845 |
24 | is($queries, 1, 'liner_notes (might_have) not prefetched - do not load |
8417f5ee |
25 | liner_notes on update'); |
26 | |
a2287768 |
27 | $schema->storage->debug($sdebug); |
8417f5ee |
28 | |
29 | |
30 | my $cd2 = $schema->resultset("CD")->find(2, {prefetch => 'liner_notes'}); |
50f18b6b |
31 | $cd2->title('test2'); |
8417f5ee |
32 | |
33 | # SELECT count |
34 | $queries = 0; |
35 | $schema->storage->debug(1); |
36 | |
37 | $cd2->update; |
38 | |
8273e845 |
39 | is($queries, 1, 'liner_notes (might_have) prefetched - do not load |
8417f5ee |
40 | liner_notes on update'); |
41 | |
dc571b76 |
42 | warning_like { |
eed5492f |
43 | local $ENV{DBIC_DONT_VALIDATE_RELS}; |
44 | |
dc571b76 |
45 | DBICTest::Schema::Bookmark->might_have( |
46 | linky => 'DBICTest::Schema::Link', |
47 | { "foreign.id" => "self.link" }, |
48 | ); |
49 | } |
50 | qr{"might_have/has_one" must not be on columns with is_nullable set to true}, |
51 | 'might_have should warn if the self.id column is nullable'; |
52 | |
53 | { |
54 | local $ENV{DBIC_DONT_VALIDATE_RELS} = 1; |
8273e845 |
55 | warning_is { |
dc571b76 |
56 | DBICTest::Schema::Bookmark->might_have( |
57 | slinky => 'DBICTest::Schema::Link', |
58 | { "foreign.id" => "self.link" }, |
59 | ); |
60 | } |
61 | undef, |
62 | 'Setting DBIC_DONT_VALIDATE_RELS suppresses nullable relation warnings'; |
63 | } |
64 | |
a2287768 |
65 | $schema->storage->debug($sdebug); |
dc571b76 |
66 | done_testing(); |