Fix the silly mistake responsible for the drama around c9733800
[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
d5907140 9my $schema = PrefetchBug->connect( DBICTest->_database (quote_char => '"') );
10ok( $schema, 'Connected to PrefetchBug schema OK' );
11
12$schema->storage->dbh->do(<<"EOF");
13CREATE TABLE prefetchbug_left (
14 id INTEGER PRIMARY KEY
15)
16EOF
17
18$schema->storage->dbh->do(<<"EOF");
19CREATE TABLE prefetchbug_right (
20 id INTEGER PRIMARY KEY,
21 name TEXT,
22 category TEXT,
23 description TEXT,
24 propagates INT,
25 locked INT
26)
27EOF
28
29$schema->storage->dbh->do(<<"EOF");
30CREATE 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)
36EOF
a48693f4 37
38# Test simple has_many prefetch:
39
40my $leftc = $schema->resultset('Left')->create({});
d5907140 41
a48693f4 42my $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
46my $left = $schema->resultset('Left')->find({ id => $leftc->id });
47
48my @left_rights = $left->search_related('prefetch_leftright', {}, { prefetch => 'right' });
49ok(defined $left_rights[0]->right, 'Prefetched Right side correctly');
50
51done_testing;