Commit | Line | Data |
92e42099 |
1 | #/usr/local/bin/perl -w |
2 | |
3 | { |
4 | package TestIntrospectableM2M::FooBar; |
5 | |
6 | use strict; |
7 | use warnings; |
8 | use base 'DBIx::Class::Core'; |
9 | |
10 | __PACKAGE__->table('foobar'); |
11 | __PACKAGE__->add_columns( |
12 | fooid => {data_type => 'integer'}, |
13 | barid => {data_type => 'integer'}, |
14 | ); |
15 | __PACKAGE__->set_primary_key(qw/fooid barid/); |
16 | __PACKAGE__->belongs_to(foo => 'TestIntrospectableM2M::Foo', { 'foreign.id' => 'self.fooid' },); |
17 | __PACKAGE__->belongs_to(bar => 'TestIntrospectableM2M::Bar', { 'foreign.id' => 'self.barid' },); |
18 | |
19 | package TestIntrospectableM2M::Foo; |
20 | |
21 | use strict; |
22 | use warnings; |
23 | use base 'DBIx::Class'; |
24 | |
25 | __PACKAGE__->load_components(qw/IntrospectableM2M Core/); |
26 | __PACKAGE__->table('foo'); |
27 | __PACKAGE__->add_columns( id => {data_type => 'integer'} ); |
28 | __PACKAGE__->has_many(foobars => 'TestIntrospectableM2M::FooBar', { 'foreign.fooid' => 'self.id' },); |
29 | __PACKAGE__->many_to_many(bars => foobars => 'bar'); |
30 | |
31 | package TestIntrospectableM2M::Bar; |
32 | |
33 | use strict; |
34 | use warnings; |
35 | use base 'DBIx::Class'; |
36 | |
37 | __PACKAGE__->load_components(qw/IntrospectableM2M Core/); |
38 | __PACKAGE__->table('bar'); |
39 | __PACKAGE__->add_columns( id => {data_type => 'integer'} ); |
40 | __PACKAGE__->has_many(foobars => 'TestIntrospectableM2M::FooBar', { 'foreign.barid' => 'self.id' },); |
41 | __PACKAGE__->many_to_many(foos => foobars => 'foo'); |
42 | } |
43 | |
44 | package main; |
45 | |
46 | use strict; |
47 | use warnings; |
48 | use Test::More tests => 3; |
49 | |
50 | my $metadata = TestIntrospectableM2M::Bar->_m2m_metadata; |
51 | |
52 | is(scalar(keys(%$metadata)), 1, 'number of keys'); |
53 | |
54 | is_deeply( [keys(%$metadata)], ['foos'], 'correct keys'); |
55 | |
56 | is_deeply( |
57 | $metadata->{foos}, |
58 | { |
59 | accessor => 'foos', |
60 | relation => 'foobars', |
61 | foreign_relation => 'foo', |
62 | rs_method => "foos_rs", |
63 | add_method => "add_to_foos", |
64 | set_method => "set_foos", |
65 | remove_method => "remove_from_foos", |
66 | }, |
67 | 'metadata hash correct', |
68 | ); |