++ed by:
ZMUGHAL ILMARI OALDERS MHOWARD ABRAXXA

24 PAUSE users
21 non-PAUSE users.

Arthur Axel "fREW" Schmidt
and 1 contributors

NAME

DBIx::Class::Helper::JoinTable - Easily set up join tables with DBIx::Class

VERSION

version 0.092970

SYNOPSIS

 package MyApp::Schema::Result::Foo_Bar;
our $VERSION = '0.092970';

 __PACKAGE__->load_components(qw{Helper::JoinTable Core});

 __PACKAGE__->join_table({
    left_class   => 'Foo',
    left_method  => 'foo',
    right_class  => 'Bar',
    right_method => 'bar',
 });

 # the above is the same as:

 __PACKAGE__->table('Foo_Bar');
 __PACKAGE__->add_columns(
    foo_id => {
       data_type         => 'integer',
       is_nullable       => 0,
       is_numeric        => 1,
    },
    bar_id => {
       data_type         => 'integer',
       is_nullable       => 0,
       is_numeric        => 1,
    },
 );

 $self->set_primary_key(qw{foo_id bar_id});

 __PACKAGE__->belongs_to( foo => 'MyApp::Schema::Result::Foo' 'foo_id');
 __PACKAGE__->belongs_to( bar => 'MyApp::Schema::Result::Bar' 'bar_id');

METHODS

All the methods take a configuration hashref that looks like the following: { left_class => 'Foo', left_method => 'foo', # see "NOTE" right_class => 'Bar', right_method => 'bar', # see "NOTE" namespace => 'MyApp', # default is guessed via *::Foo }

join_table

This is the method that you probably want. It will set your table, add columns, set the primary key, and set up the relationships.

add_join_columns

Adds two non-nullable integer fields named "${left_method}_id" and "${right_method}_id" respectively.

generate_primary_key

Sets "${left_method}_id" and "${right_method}_id" to be the primary key.

generate_relationships

This adds relationships to "${namespace}::Schema::Result::$left_class" and "${namespace}::Schema::Result::$left_class" respectively.

set_table

This method sets the table to "${left_class}_${right_class}".

NOTE

This module uses String::CamelCase to default the method names if it is installed. Currently it fails pod tests, so I'm not making it a requirement.

AUTHOR

  Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2009 by Arthur Axel "fREW" Schmidt.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.