Commit | Line | Data |
7adfd53f |
1 | package # hide from PAUSE |
2 | RTest::TestDB::Foo; |
3 | |
df9a9c12 |
4 | use base qw/DBIx::Class/; |
082e6aee |
5 | use metaclass 'Reaction::Meta::Class'; |
6 | use Moose; |
7adfd53f |
7 | |
082e6aee |
8 | use MooseX::Types::Moose qw/ArrayRef Int/; |
9 | use Reaction::Types::Core qw/NonEmptySimpleStr/; |
7adfd53f |
10 | |
082e6aee |
11 | has 'id' => (isa => Int, is => 'ro', required => 1); |
ed6d9da8 |
12 | has 'first_name' => (isa => NonEmptySimpleStr, is => 'rw', required => 1); |
13 | has 'last_name' => (isa => NonEmptySimpleStr, is => 'rw', required => 1); |
80436b58 |
14 | has 'bars' => (isa => ArrayRef, is => 'ro' ); |
df9a9c12 |
15 | has 'bazes' => |
082e6aee |
16 | ( |
17 | isa => ArrayRef, |
18 | required => 1, |
df9a9c12 |
19 | reader => 'get_bazes', |
20 | writer => 'set_bazes' |
7adfd53f |
21 | ); |
22 | |
082e6aee |
23 | use namespace::clean -except => [ 'meta' ]; |
7adfd53f |
24 | |
df9a9c12 |
25 | __PACKAGE__->load_components(qw/IntrospectableM2M Core/); |
7adfd53f |
26 | __PACKAGE__->table('foo'); |
27 | |
28 | __PACKAGE__->add_columns( |
29 | id => { data_type => 'integer', size => 16, is_auto_increment => 1 }, |
30 | first_name => { data_type => 'varchar', size => 255 }, |
31 | last_name => { data_type => 'varchar', size => 255 }, |
32 | ); |
33 | |
7adfd53f |
34 | __PACKAGE__->set_primary_key('id'); |
35 | |
510f6c25 |
36 | __PACKAGE__->has_many( |
37 | 'bars' => 'RTest::TestDB::Bar', |
38 | { 'foreign.foo_id' => 'self.id' } |
39 | ); |
40 | |
df9a9c12 |
41 | __PACKAGE__->has_many('foo_baz' => 'RTest::TestDB::FooBaz', 'foo'); |
42 | __PACKAGE__->many_to_many('bazes' => 'foo_baz' => 'baz'); |
7adfd53f |
43 | |
082e6aee |
44 | sub display_name { |
45 | my $self = shift; |
46 | return join(' ', $self->first_name, $self->last_name); |
7adfd53f |
47 | } |
48 | |
510f6c25 |
49 | around get_bazes => sub { [ $_[1]->bazes_rs->all ] }; |
a5200252 |
50 | |
c689b58e |
51 | __PACKAGE__->meta->make_immutable(inline_constructor => 0); |
a5200252 |
52 | |
7adfd53f |
53 | 1; |