man DBIx::Class::Relationship::Base () - Inter-table relationships
NAME
DBIx::Class::Relationship::Base - Inter-table relationships
SYNOPSIS
DESCRIPTION
This class handles relationships between the tables in your database model. It allows your to set up relationships, and to perform joins on searches.
METHODS
add_relationship
__PACKAGE__->add_relationship('relname', 'Foreign::Class', $cond, $attrs);
The condition needs to be an SQL::Abstract-style representation of the join between the tables. For example, if you're creating a rel from Foo to Bar,
{ 'foreign.foo_id' => 'self.id' }
will result in the JOIN clause
foo me JOIN bar bar ON bar.foo_id = me.id
You can specify as many foreign => self mappings as necessary.
Valid attributes are as follows:
- join_type
- Explicitly specifies the type of join to use in the relationship. Any SQL join type is valid, e.g. CWLEFT or CWRIGHT. It will be placed in the SQL command immediately before CWJOIN.
- proxy
-
An arrayref containing a list of accessors in the foreign class to proxy in
the main class. If, for example, you do the following:
__PACKAGE__->might_have(bar => 'Bar', undef, { proxy => qw[/ margle /] });
Then, assuming Bar has an accessor named margle, you can do:my $obj = Foo->find(1); $obj->margle(1); # set margle; Bar object is created if it doesn't exist
- accessor
- Specifies the type of accessor that should be created for the relationship. Valid values are CWsingle (for when there is only a single related object), CWmulti (when there can be many), and CWfilter (for when there is a single related object, but you also want the relationship accessor to double as a column accessor). For CWmulti accessors, an add_to_* method is also created, which calls CWcreate_related for the relationship.
search_related
My::Table->search_related('relname', $cond, $attrs);
count_related
My::Table->count_related('relname', $cond, $attrs);
create_related
My::Table->create_related('relname', \%col_data);
new_related
My::Table->new_related('relname', \%col_data);
find_related
My::Table->find_related('relname', @pri_vals | \%pri_vals);
find_or_create_related
My::Table->find_or_create_related('relname', \%col_data);
set_from_related
My::Table->set_from_related('relname', $rel_obj);
update_from_related
My::Table->update_from_related('relname', $rel_obj);
delete_related
My::Table->delete_related('relname', $cond, $attrs);
AUTHORS
Matt S. Trout <mst@shadowcatsystems.co.uk>
LICENSE
You may distribute this code under the same terms as Perl itself.