Fold column_info() into columns_info()
[dbsrgits/DBIx-Class.git] / t / 86might_have.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
70350518 3use strict;
8273e845 4use warnings;
70350518 5
6use Test::More;
dc571b76 7use Test::Warn;
c0329273 8
70350518 9use DBICTest;
10
a47e1233 11my $schema = DBICTest->init_schema();
8417f5ee 12
8417f5ee 13my $cd = $schema->resultset("CD")->find(1);
14$cd->title('test');
15
49eeb48d 16$schema->is_executed_querycount( sub {
17 $cd->update;
18}, {
19 BEGIN => 1,
20 UPDATE => 1,
21 COMMIT => 1,
22}, 'liner_notes (might_have) not prefetched - do not load liner_notes on update' );
8417f5ee 23
24my $cd2 = $schema->resultset("CD")->find(2, {prefetch => 'liner_notes'});
50f18b6b 25$cd2->title('test2');
8417f5ee 26
49eeb48d 27$schema->is_executed_querycount( sub {
28 $cd2->update;
29}, {
30 BEGIN => 1,
31 UPDATE => 1,
32 COMMIT => 1,
33}, 'liner_notes (might_have) prefetched - do not load liner_notes on update');
8417f5ee 34
dc571b76 35warning_like {
eed5492f 36 local $ENV{DBIC_DONT_VALIDATE_RELS};
37
dc571b76 38 DBICTest::Schema::Bookmark->might_have(
39 linky => 'DBICTest::Schema::Link',
40 { "foreign.id" => "self.link" },
41 );
42}
b83736a7 43 qr{'might_have'/'has_one' must not be used on columns with is_nullable set to true},
dc571b76 44 'might_have should warn if the self.id column is nullable';
45
46{
47 local $ENV{DBIC_DONT_VALIDATE_RELS} = 1;
8273e845 48 warning_is {
dc571b76 49 DBICTest::Schema::Bookmark->might_have(
50 slinky => 'DBICTest::Schema::Link',
51 { "foreign.id" => "self.link" },
52 );
53 }
54 undef,
55 'Setting DBIC_DONT_VALIDATE_RELS suppresses nullable relation warnings';
56}
57
dc571b76 58done_testing();