Fix the silly mistake responsible for the drama around c9733800
[dbsrgits/DBIx-Class.git] / t / prefetch / undef_prefetch_bug.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7 use PrefetchBug;
8
9 my $schema = PrefetchBug->connect( DBICTest->_database (quote_char => '"') );
10 ok( $schema, 'Connected to PrefetchBug schema OK' );
11
12 $schema->storage->dbh->do(<<"EOF");
13 CREATE TABLE prefetchbug_left (
14   id INTEGER PRIMARY KEY
15 )
16 EOF
17
18 $schema->storage->dbh->do(<<"EOF");
19 CREATE TABLE prefetchbug_right (
20   id INTEGER PRIMARY KEY,
21   name TEXT,
22   category TEXT,
23   description TEXT,
24   propagates INT,
25   locked INT
26 )
27 EOF
28
29 $schema->storage->dbh->do(<<"EOF");
30 CREATE TABLE prefetchbug_left_right (
31   left_id INTEGER REFERENCES prefetchbug_left(id),
32   right_id INTEGER REFERENCES prefetchbug_right(id),
33   value TEXT,
34   PRIMARY KEY (left_id, right_id)
35 )
36 EOF
37
38 # Test simple has_many prefetch:
39
40 my $leftc = $schema->resultset('Left')->create({});
41
42 my $rightc = $schema->resultset('Right')->create({ id => 60, name => 'Johnny', category => 'something', description=> 'blah', propagates => 0, locked => 1 });
43 $rightc->create_related('prefetch_leftright', { left => $leftc, value => 'lr' });
44
45 # start with fresh whatsit
46 my $left = $schema->resultset('Left')->find({ id => $leftc->id });
47
48 my @left_rights = $left->search_related('prefetch_leftright', {}, { prefetch => 'right' });
49 ok(defined $left_rights[0]->right, 'Prefetched Right side correctly');
50
51 done_testing;