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