1DBIx::Class::Helper::RoUws:e:rJoCionnTtarbilbeu(t3e)d PeDrBlIxD:o:cCulmaesnst:a:tHieolnper::Row::JoinTable(3)
2
3
4

NAME

6       DBIx::Class::Helper::Row::JoinTable - Easily set up join tables with
7       DBIx::Class
8

SYNOPSIS

10        package MyApp::Schema::Result::Foo_Bar;
11
12        __PACKAGE__->load_components(qw{Helper::Row::JoinTable Core});
13
14        __PACKAGE__->join_table({
15           left_class   => 'Foo',
16           left_method  => 'foo',
17           right_class  => 'Bar',
18           right_method => 'bar',
19        });
20
21        # the above is the same as:
22
23        __PACKAGE__->table('Foo_Bar');
24        __PACKAGE__->add_columns(
25           foo_id => {
26              data_type         => 'integer',
27              is_nullable       => 0,
28              is_numeric        => 1,
29           },
30           bar_id => {
31              data_type         => 'integer',
32              is_nullable       => 0,
33              is_numeric        => 1,
34           },
35        );
36
37        $self->set_primary_key(qw{foo_id bar_id});
38
39        __PACKAGE__->belongs_to( foo => 'MyApp::Schema::Result::Foo' 'foo_id');
40        __PACKAGE__->belongs_to( bar => 'MyApp::Schema::Result::Bar' 'bar_id');
41
42       or with DBIx::Class::Candy:
43
44        package MyApp::Schema::Result::Foo_Bar;
45
46        use DBIx::Class::Candy -components => ['Helper::Row::JoinTable'];
47
48        join_table {
49           left_class   => 'Foo',
50           left_method  => 'foo',
51           right_class  => 'Bar',
52           right_method => 'bar',
53        };
54

METHODS

56       All the methods take a configuration hashref that looks like the
57       following:
58
59        {
60           left_class          => 'Foo',
61           left_method         => 'foo',     # see NOTE
62           left_method_plural  => 'foos',    # see NOTE, not required, used for
63                                             # many_to_many rel name in right_class
64                                             # which is not generated by default
65           right_class         => 'Bar',
66           right_method        => 'bar',     # see NOTE
67           right_method_plural => 'bars',    # see NOTE, not required, used for
68                                             # many_to_many rel name in left_class
69                                             # which is not generated by default
70           namespace           => 'MyApp',   # default is guessed via *::Foo
71           self_method         => 'foobars', # not required, used for setting the name of the
72                                             # join table's relationship in a has_many
73                                             # which is not generated by default
74        }
75
76   join_table
77       This is the method that you probably want.  It will set your table, add
78       columns, set the primary key, and set up the relationships.
79
80   add_join_columns
81       Adds two non-nullable integer fields named "${left_method}_id" and
82       "${right_method}_id" respectively.
83
84   generate_has_manys
85       Installs methods into "left_class" and "right_class" to get to the join
86       table.  The methods will be named what's passed into the configuration
87       hashref as "self_method".
88
89   generate_many_to_manys
90       Installs many_to_many methods into "left_class" and "right_class".  The
91       methods will be named what's passed into the configuration hashref as
92       "left_method_plural" for the "right_class" and "right_method_plural"
93       for the "left_class".
94
95   generate_primary_key
96       Sets "${left_method}_id" and "${right_method}_id" to be the primary
97       key.
98
99   generate_relationships
100       This adds relationships to "${namespace}::Schema::Result::$left_class"
101       and "${namespace}::Schema::Result::$left_class" respectively.
102
103   set_table
104       This method sets the table to "${left_class}_${right_class}".
105

CANDY EXPORTS

107       If used in conjunction with DBIx::Class::Candy this component will
108       export:
109
110       join_table
111       generate_primary_key
112       generate_has_manys
113       generate_many_to_manys
114       generate_relationships
115       set_table
116       add_join_columns
117
118   NOTE
119       This module uses (an internal fork of) String::CamelCase to default the
120       method names and uses Lingua::EN::Inflect for pluralization.
121

CHANGES BETWEEN RELEASES

123   Changes since 0.*
124       Originally this module would use
125
126              data_type         => 'integer',
127              is_nullable       => 0,
128              is_numeric        => 1,
129
130       for all joining columns.  It now infers "data_type", "is_nullable",
131       "is_numeric", and "extra" from the foreign tables.
132

AUTHOR

134       Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
135
137       This software is copyright (c) 2019 by Arthur Axel "fREW" Schmidt.
138
139       This is free software; you can redistribute it and/or modify it under
140       the same terms as the Perl 5 programming language system itself.
141
142
143
144perl v5.30.1                      2020-01D-B2I9x::Class::Helper::Row::JoinTable(3)
Impressum