New test for recent prefetch/undef bug
[dbsrgits/DBIx-Class.git] / t / prefetch / undef_prefetch_bug.t
CommitLineData
a48693f4 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7use PrefetchBug;
8
9BEGIN {
10 require DBIx::Class;
11 plan skip_all => 'Test needs ' .
12 DBIx::Class::Optional::Dependencies->req_missing_for('deploy')
13 unless DBIx::Class::Optional::Dependencies->req_ok_for('deploy');
14}
15
16 my $schema
17 = PrefetchBug->connect( DBICTest->_database (quote_char => '"') );
18 ok( $schema, 'Connected to PrefetchBug schema OK' );
19
20#################### DEPLOY
21
22 $schema->deploy( { add_drop_table => 1 } );
23
24# Test simple has_many prefetch:
25
26my $leftc = $schema->resultset('Left')->create({});
27my $rightc = $schema->resultset('Right')->create({ id => 60, name => 'Johnny', category => 'something', description=> 'blah', propagates => 0, locked => 1 });
28$rightc->create_related('prefetch_leftright', { left => $leftc, value => 'lr' });
29
30# start with fresh whatsit
31my $left = $schema->resultset('Left')->find({ id => $leftc->id });
32
33my @left_rights = $left->search_related('prefetch_leftright', {}, { prefetch => 'right' });
34ok(defined $left_rights[0]->right, 'Prefetched Right side correctly');
35
36done_testing;