9 # The test must be performed on non-registered result classes
12 package DBICTest::Thing;
15 use base qw/DBIx::Class::Core/;
16 __PACKAGE__->table('thing');
17 __PACKAGE__->add_columns(qw/id ancestor_id/);
18 __PACKAGE__->set_primary_key('id');
19 __PACKAGE__->has_many(children => __PACKAGE__, 'id');
20 __PACKAGE__->belongs_to(parent => __PACKAGE__, 'id', { join_type => 'left' } );
22 __PACKAGE__->has_many(subthings => 'DBICTest::SubThing', 'thing_id');
26 package DBICTest::SubThing;
29 use base qw/DBIx::Class::Core/;
30 __PACKAGE__->table('subthing');
31 __PACKAGE__->add_columns(qw/thing_id/);
32 __PACKAGE__->belongs_to(thing => 'DBICTest::Thing', 'thing_id');
33 __PACKAGE__->belongs_to(thing2 => 'DBICTest::Thing', 'thing_id', { join_type => 'left' } );
36 my $schema = DBICTest->init_schema;
38 for my $without_schema (1,0) {
40 my ($t, $s) = $without_schema
41 ? (qw/DBICTest::Thing DBICTest::SubThing/)
43 $schema->register_class(relinfo_thing => 'DBICTest::Thing');
44 $schema->register_class(relinfo_subthing => 'DBICTest::SubThing');
46 map { $schema->source ($_) } qw/relinfo_thing relinfo_subthing/;
51 [ sort $t->relationships ],
52 [qw/ children parent subthings/],
53 "Correct relationships on $t",
57 [ sort $s->relationships ],
59 "Correct relationships on $s",
63 _instance($s)->reverse_relationship_info('thing'),
64 { subthings => $t->relationship_info('subthings') },
65 'reverse_rel_info works cross-class belongs_to direction',
68 _instance($s)->reverse_relationship_info('thing2'),
69 { subthings => $t->relationship_info('subthings') },
70 'reverse_rel_info works cross-class belongs_to direction 2',
74 _instance($t)->reverse_relationship_info('subthings'),
75 { map { $_ => $s->relationship_info($_) } qw/thing thing2/ },
76 'reverse_rel_info works cross-class has_many direction',
80 _instance($t)->reverse_relationship_info('parent'),
81 { children => $t->relationship_info('children') },
82 'reverse_rel_info works in-class belongs_to direction',
85 _instance($t)->reverse_relationship_info('children'),
86 { parent => $t->relationship_info('parent') },
87 'reverse_rel_info works in-class has_many direction',
92 $_[0]->isa('DBIx::Class::ResultSource')
94 : $_[0]->result_source_instance