Commit | Line | Data |
62fa8aec |
1 | package #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 | |
11 | DBICNGTest::Schema::Result::Person; An example Person Class; |
12 | |
13 | =head1 DESCRIPTION |
14 | |
15 | Tests for this type of FK relationship |
16 | |
17 | =head1 ATTRIBUTES |
18 | |
19 | This class defines the following attributes. |
20 | |
21 | =head2 created |
22 | |
23 | attribute for the created column |
24 | |
25 | =cut |
26 | |
27 | has '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 | |
39 | This module defines the following package methods |
40 | |
41 | =head2 table |
42 | |
43 | Name of the Physical table in the database |
44 | |
45 | =cut |
46 | |
47 | __PACKAGE__ |
48 | ->table('person'); |
49 | |
50 | |
51 | =head2 add_columns |
52 | |
53 | Add columns and meta information |
54 | |
55 | =head3 person_id |
56 | |
57 | Primary Key which is an auto generated autoinc |
58 | |
59 | =head3 fk_gender_id |
60 | |
61 | foreign key to the Gender table |
62 | |
63 | =head3 name |
64 | |
65 | Just an ordinary name |
66 | |
67 | =head3 age |
68 | |
69 | The person's age |
70 | |
71 | head3 created |
72 | |
73 | When 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 | |
101 | Sets 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 | |
111 | Each 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 | |
123 | This 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 | |
134 | A 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 | |
145 | A 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 | |
155 | A 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 | |
165 | This module defines the following methods. |
166 | |
167 | =head1 AUTHORS |
168 | |
169 | See L<DBIx::Class> for more information regarding authors. |
170 | |
171 | =head1 LICENSE |
172 | |
173 | You may distribute this code under the same terms as Perl itself. |
174 | |
175 | =cut |
176 | |
177 | |
178 | 1; |