item => head2 in docs
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Relationship.pm
CommitLineData
b8e1e21f 1package DBIx::Class::Relationship;
2
3use strict;
4use warnings;
5
1edd1722 6use base qw/DBIx::Class/;
55e2d745 7
07037f89 8__PACKAGE__->load_own_components(qw/
9 HasMany
10 HasOne
11 BelongsTo
12 Accessor
13 CascadeActions
14 ProxyMethods
15 Base
16/);
b8e1e21f 17
18__PACKAGE__->mk_classdata('_relationships', { } );
19
34d52be2 20=head1 NAME
21
22DBIx::Class::Relationship - Inter-table relationships
23
24=head1 SYNOPSIS
25
26=head1 DESCRIPTION
27
28This class handles relationships between the tables in your database
df8abd99 29model. It allows you to set up relationships and perform joins on them.
34d52be2 30
df8abd99 31Only the helper methods for setting up standard relationship types
32are documented here. For the basic, lower-level methods, see
33L<DBIx::Class::Relationship::Base>.
503536d5 34
34d52be2 35=head1 METHODS
36
df8abd99 37All helper methods take the following arguments:
503536d5 38
df8abd99 39 __PACKAGE__>method_name('relname', 'Foreign::Class', $cond, $attrs);
40
41Both C<$cond> and C<$attrs> are optional. Pass C<undef> for C<$cond> if
42you want to use the default value for it, but still want to set C<$attrs>.
43The following attributes are recognize:
503536d5 44
130c6439 45=head2 join_type
503536d5 46
df8abd99 47Explicitly specifies the type of join to use in the relationship. Any SQL
48join type is valid, e.g. C<LEFT> or C<RIGHT>. It will be placed in the SQL
49command immediately before C<JOIN>.
34d52be2 50
130c6439 51=head2 proxy
503536d5 52
df8abd99 53An arrayref containing a list of accessors in the foreign class to proxy in
54the main class. If, for example, you do the following:
55
56 __PACKAGE__->might_have(bar => 'Bar', undef, { proxy => qw[/ margle /] });
57
58Then, assuming Bar has an accessor named margle, you can do:
503536d5 59
df8abd99 60 my $obj = Foo->find(1);
61 $obj->margle(10); # set margle; Bar object is created if it doesn't exist
62
df8abd99 63=head2 belongs_to
503536d5 64
65 my $f_obj = $obj->relname;
66
df8abd99 67 $obj->relname($new_f_obj);
68
69Creates a relationship where we store the foreign class' PK; if $join is a
70column name instead of a condition that is assumed to be the FK, if not
71has_many assumes the FK is the relname is that is a column on the current
72class.
503536d5 73
df8abd99 74=head2 has_many
503536d5 75
76 my @f_obj = $obj->relname($cond?, $attrs?);
77 my $f_result_set = $obj->relname($cond?, $attrs?);
78
79 $obj->add_to_relname(\%col_data);
80
81Creates a one-many relationship with another class;
82
df8abd99 83=head2 might_have
503536d5 84
85 my $f_obj = $obj->relname;
86
df8abd99 87Creates an optional one-one relationship with another class; defaults to PK-PK
88for the join condition unless a condition is specified.
503536d5 89
df8abd99 90=head2 has_one
91
92 my $f_obj = $obj->relname;
93
94Creates a one-one relationship with another class; defaults to PK-PK for
95the join condition unless a condition is specified.
503536d5 96
34d52be2 97=cut
98
b8e1e21f 991;
34d52be2 100
34d52be2 101=head1 AUTHORS
102
daec44b8 103Matt S. Trout <mst@shadowcatsystems.co.uk>
34d52be2 104
105=head1 LICENSE
106
107You may distribute this code under the same terms as Perl itself.
108
109=cut
110