querycounter role, test for that and a new schema hierarchy for additional Moose...
[dbsrgits/DBIx-Class.git] / t / lib / DBICNGTest / Schema / Result / Person.pm
CommitLineData
62fa8aec 1package #hide from pause
2 DBICNGTest::Schema::Result::Person;
3
4 use Moose;
5 use DateTime;
6 extends 'DBICNGTest::Schema::Result';
7
8
9=head1 NAME
10
11DBICNGTest::Schema::Result::Person; An example Person Class;
12
13=head1 DESCRIPTION
14
15Tests for this type of FK relationship
16
17=head1 ATTRIBUTES
18
19This class defines the following attributes.
20
21=head2 created
22
23attribute for the created column
24
25=cut
26
27has 'created' => (
28 is=>'ro',
29 isa=>'DateTime',
30 required=>1,
31 default=>sub {
32 DateTime->now;
33 },
34);
35
36
37=head1 PACKAGE METHODS
38
39This module defines the following package methods
40
41=head2 table
42
43Name of the Physical table in the database
44
45=cut
46
47__PACKAGE__
48 ->table('person');
49
50
51=head2 add_columns
52
53Add columns and meta information
54
55=head3 person_id
56
57Primary Key which is an auto generated autoinc
58
59=head3 fk_gender_id
60
61foreign key to the Gender table
62
63=head3 name
64
65Just an ordinary name
66
67=head3 age
68
69The person's age
70
71head3 created
72
73When the person was added to the database
74
75=cut
76
77__PACKAGE__
78 ->add_columns(
79 person_id => {
80 data_type=>'integer',
81 },
82 fk_gender_id => {
83 data_type=>'integer',
84 },
85 name => {
86 data_type=>'varchar',
87 size=>32,
88 },
89 age => {
90 data_type=>'integer',
91 default_value=>25,
92 },
93 created => {
94 data_type=>'datetime',
95 default_value=>'date("now")',
96 });
97
98
99=head2 primary_key
100
101Sets the Primary keys for this table
102
103=cut
104
105__PACKAGE__
106 ->set_primary_key(qw/person_id/);
107
108
109=head2 friendlist
110
111Each Person might have a resultset of friendlist
112
113=cut
114
115__PACKAGE__
116 ->has_many(
117 friendlist => 'DBICNGTest::Schema::Result::FriendList',
118 {'foreign.fk_person_id' => 'self.person_id'});
119
120
121=head2 gender
122
123This person's gender
124
125=cut
126
127__PACKAGE__
128 ->belongs_to( gender => 'DBICNGTest::Schema::Result::Gender', {
129 'foreign.gender_id' => 'self.fk_gender_id' });
130
131
132=head2 fanlist
133
134A resultset of the people listing me as a friend (if any)
135
136=cut
137
138__PACKAGE__
139 ->belongs_to( fanlist => 'DBICNGTest::Schema::Result::FriendList', {
140 'foreign.fk_friend_id' => 'self.person_id' });
141
142
143=head2 friends
144
145A resultset of Persons who are in my FriendList
146
147=cut
148
149__PACKAGE__
150 ->many_to_many( friends => 'friendlist', 'friend' );
151
152
153=head2 fans
154
155A resultset of people that have me in their friendlist
156
157=cut
158
159__PACKAGE__
160 ->many_to_many( fans => 'fanlist', 'befriender' );
161
162
163=head1 METHODS
164
165This module defines the following methods.
166
167=head1 AUTHORS
168
169See L<DBIx::Class> for more information regarding authors.
170
171=head1 LICENSE
172
173You may distribute this code under the same terms as Perl itself.
174
175=cut
176
177
1781;