add manual descriptions
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Manual / Cookbook.pod
CommitLineData
3b44ccc6 1=head1 NAME
9c82c181 2
3b44ccc6 3DBIx::Class::Manual::Cookbook - Misc receipes
ee38fa40 4
5=over 4
6
7=item Input validation.
8
9=item Using joins
10
11=item Many-to-many relationships
12
13This is not as easy as it could be, but it's possible. Here's an example to
14illustrate:
15
16 package Base;
17
18 use base qw/DBIx::Class/;
19
20 __PACKAGE__->load_components(qw/Core DB/);
21 __PACKAGE__->connection(...);
22
23 package Left;
24
25 use base qw/Base/;
26
27 __PACKAGE__->table('left');
28 __PACKAGE__->add_columns(qw/id left_stuff/);
29 __PACKAGE__->set_primary_key(qw/id/);
30 __PACKAGE__->has_many('mid' => 'Mid');
31
32 sub right {
33 my ($self) = @_;
34 return Right->search(
35 { 'left.id' => $self->id },
36 { join => { 'mid' => 'left' }});
37 }
38
39 package Mid;
40
41 use base qw/Base/;
42
43 __PACKAGE__->table('mid');
44 __PACKAGE__->add_columns(qw/left right/);
45 __PACKAGE__->set_primary_key(qw/left right/);
46
47 __PACKAGE__->belongs_to('left' => 'Left');
48 __PACKAGE__->belongs_to('right' => 'Right');
49
50 package Right;
51
52 use base qw/Base/;
53
54 __PACKAGE__->table('right');
55 __PACKAGE__->add_columns(qw/id right_stuff/);
56 __PACKAGE__->set_primary_key(qw/id/);
57 __PACKAGE__->has_many('mid' => 'Mid');
58
59 sub left {
60 my ($self) = @_;
61 return Left->search(
62 { 'right.id' => $self->id },
63 { join => { 'mid' => 'right' });
64 }
65
66=item Advanced Exception handling
67
68=item Transactions
69
70=back