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