new component to make m2ms introspectables so we can hint the reflector
[catagits/Reaction.git] / t / lib / RTest / TestDB / Foo.pm
1 package # hide from PAUSE
2   RTest::TestDB::Foo;
3
4 use base qw/DBIx::Class/;
5 use metaclass 'Reaction::Meta::Class';
6 use Moose;
7
8 use MooseX::Types::Moose qw/ArrayRef Int/;
9 use Reaction::Types::Core qw/NonEmptySimpleStr/;
10
11 has 'id' => (isa => Int, is => 'ro', required => 1);
12 has 'first_name' => (isa => NonEmptySimpleStr, is => 'rw', required => 1);
13 has 'last_name' => (isa => NonEmptySimpleStr, is => 'rw', required => 1);
14 has 'bazes' =>
15   (
16    isa => ArrayRef,
17    required => 1,
18    reader => 'get_bazes',
19    writer => 'set_bazes'
20 );
21
22 use namespace::clean -except => [ 'meta' ];
23
24 __PACKAGE__->load_components(qw/IntrospectableM2M Core/);
25 __PACKAGE__->table('foo');
26
27 __PACKAGE__->add_columns(
28   id => { data_type => 'integer', size => 16, is_auto_increment => 1 },
29   first_name => { data_type => 'varchar', size => 255 },
30   last_name => { data_type => 'varchar', size => 255 },
31 );
32
33 __PACKAGE__->set_primary_key('id');
34
35 __PACKAGE__->has_many('foo_baz' => 'RTest::TestDB::FooBaz', 'foo');
36 __PACKAGE__->many_to_many('bazes' => 'foo_baz' => 'baz');
37
38 sub display_name {
39   my $self = shift;
40   return join(' ', $self->first_name, $self->last_name);
41 }
42
43 sub get_bazes { [ shift->bazes_rs->all ] };
44
45 __PACKAGE__->meta->make_immutable(inline_constructor => 0);
46
47 1;