Andy Grundman > DBIx-Class-0.03003 > DBIx::Class::Manual::Cookbook

Download:
DBIx-Class-0.03003.tar.gz

Annotate this POD (2)

CPAN RT

New  14
Open  19
Stalled  12
View/Report Bugs
Source   Latest Release: DBIx-Class-0.082899_14

NAME ^

DBIx::Class::Manual::Cookbook

Input validation.
Using joins
Many-to-many relationships

This is not as easy as it could be, but it's possible. Here's an example to illustrate:

    package Base; 

    use base qw/DBIx::Class/;

    __PACKAGE__->load_components(qw/Core DB/);
    __PACKAGE__->connection(...);

    package Left;

    use base qw/Base/;

    __PACKAGE__->table('left');
    __PACKAGE__->add_columns(qw/id left_stuff/);
    __PACKAGE__->set_primary_key(qw/id/);
    __PACKAGE__->has_many('mid' => 'Mid');

    sub right {
     my ($self) = @_;
     return Right->search(
       { 'left.id' => $self->id },
       { join => { 'mid' => 'left' }});
    }

    package Mid;

    use base qw/Base/;

    __PACKAGE__->table('mid');
    __PACKAGE__->add_columns(qw/left right/);
    __PACKAGE__->set_primary_key(qw/left right/);

    __PACKAGE__->belongs_to('left' => 'Left');
    __PACKAGE__->belongs_to('right' => 'Right');

    package Right;

    use base qw/Base/;

    __PACKAGE__->table('right');
    __PACKAGE__->add_columns(qw/id right_stuff/);
    __PACKAGE__->set_primary_key(qw/id/);
    __PACKAGE__->has_many('mid' => 'Mid');

    sub left {
     my ($self) = @_;
     return Left->search(
       { 'right.id' => $self->id },
       { join => { 'mid' => 'right' });
    }
Advanced Exception handling
Transactions
syntax highlighting: