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