6 @INC{qw(Test::Schema::Foo Test::Schema::Baz)} = (1) x 2;
8 package Test::Schema::Foo;
9 use parent 'DBIx::Class';
10 __PACKAGE__->load_components(qw(Core));
11 __PACKAGE__->table('foo');
12 __PACKAGE__->add_columns(qw(id bar_id));
13 __PACKAGE__->set_primary_key('id');
14 __PACKAGE__->belongs_to(
15 baz => 'Test::Schema::Baz',
16 { 'foreign.id' => 'self.bar_id' }
19 package Test::Schema::Baz;
20 use parent 'DBIx::Class';
21 __PACKAGE__->load_components(qw(Core));
22 __PACKAGE__->table('baz');
23 __PACKAGE__->add_columns(qw(id quux));
24 __PACKAGE__->set_primary_key('id');
25 __PACKAGE__->has_many(
26 foos => 'Test::Schema::Foo' => { 'foreign.bar_id' => 'self.id' } );
29 use parent 'DBIx::Class::Schema';
30 __PACKAGE__->register_source(
31 $_ => "Test::Schema::$_"->result_source_instance )
36 my $schema = Test::Schema->connect( 'dbi:SQLite:dbname=:memory:', '', '' );
39 my $foo_rs = $schema->resultset('Foo');
40 # create a condition that guarantees all values have 0 in them,
41 # which makes the inflation process skip the row because of:
42 # next unless first { defined $_ } values %{$me_pref->[0]};
43 # all values need to be zero to ensure that the arbitrary order in
44 # which values() returns the results doesn't break the test
45 $foo_rs->create( { id => 0, baz => { id => 0, quux => 0 } } );
47 my $baz_rs = $schema->resultset('Baz');
48 ok( $baz_rs->search( {}, { prefetch => 'foos' } )->first->foos->first );
53 $foo_rs->create( { id => 1, baz => { id => 1, quux => 1 } } );
54 ok( $baz_rs->search( {}, { prefetch => 'foos' } )->first->foos->first );