DBICx::MapMaker - automatically create a DBIx::Class mapping table
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
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
MapMaker. See "ATTRIBUTES" below for a description of the attributes you can pass to the constructor.
$class into the mapping table.
$class should be a subclass of
Here are the attributes that you can pass to the constructor:
The class name of the left/right table (the tables that have a m2m relationship between them).
The column name for the left/right table's primary key in the map table.
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
left_to_map_relation will be
The name of the m2m relationship.
rights_from_left is the method you'll call on a
left row to get the corresponding
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.
The name of the created mapping table.
Optional. Defaults to "map_
Copyright 2008 Infinity Interactive, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Jonathan Rockway <firstname.lastname@example.org>
This software is copyright (c) 2011 by Jonathan Rockway.