DBICx::MapMaker(3)

NAME
DBICx::MapMaker - automatically create a DBIx::Class mapping table

VERSION
version 0.03

SYNOPSIS
A common SQL pattern is the "many to many" relationship; a row in the "left table" may point to many rows in the "right table", and a row in the "right table" may point to many rows in the "left table". This module automatically creates a DBIx::Class result source for that table, and sets up the six necessary relationships.

Here's how to use it. Imagine you have some tables called "MySchema::A" and "MySchema::B", each with a primary key, that you'd like to join. To create the mapping table, you'll write a module like this:

  package MySchema::MapAB;
  use DBICx::MapMaker;
  use base 'DBIx::Class';

  my $map = DBICx::MapMaker->new(
      left_class  => 'MySchema::A',
      right_class => 'MySchema::B',
      left_name   => 'a',
      right_name  => 'b',
  );

  $map->setup_table(__PACKAGE__);

Then, you can:

  my $a = $schema->resultset('A')->find(1);
  $a->b_map; # the mapping table
  $a->bs;    # a list of bs that this a has

  my $b = $schema->resultset('B')->find(42);
  $b->a_map; # the mapping table
  $b->as;    # a list of as that this b has

METHODS

  new
Create a "MapMaker". See "ATTRIBUTES" below for a description of the attributes you can pass to the constructor.

  setup_table($class)
Makes $class into the mapping table. $class should be a subclass of "DBIx::Class".

ATTRIBUTES
Here are the attributes that you can pass to the constructor:

  left_class right_class
The class name of the left/right table (the tables that have a m2m relationship between them).

Required.

  left_name right_name
The column name for the left/right table's primary key in the map table.

Required.

  left_to_map_relation right_to_map_relation
The name of the relationship from the left/right table to the map table.

Optional. Defaults to the name of the opposite table's name with "_map" appended. (If "right_name" is "foo", then "left_to_map_relation" will be "foo_map".)

  rights_from_left lefts_from_right
The name of the m2m relationship. "rights_from_left" is the method you'll call on a "left" row to get the corresponding "right"s. ("lefts_from_right" is the opposite.)

Optional. Defaults to the name of the row returned with "s" appended. If "left_name" is "foo", then "lefts_from_right" will be "foos" by default.

  tablename
The name of the created mapping table.

Optional. Defaults to "map_"left_name"_"right_name"". (With "foo" and "bar", "map_foo_bar".)

AUTHORS
Jonathan Rockway "<jrockway@cpan.org>"

Stevan Little "<stevan.little@iinteractive.com>"

Adam Herzog "<adam@adamherzog.com>"

COPYRIGHT AND LICENSE
Copyright 2008 Infinity Interactive, Inc.

<http://www.iinteractive.com>

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

AUTHOR
Jonathan Rockway <jrockway@cpan.org>

COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Jonathan Rockway.

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