GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
DBICx::MapMaker(3) User Contributed Perl Documentation DBICx::MapMaker(3)

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

version 0.03

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

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

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

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).

Required.

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

Required.

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".)

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.

The name of the created mapping table.

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

Jonathan Rockway "<jrockway@cpan.org>"

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

Adam Herzog "<adam@adamherzog.com>"

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.

Jonathan Rockway <jrockway@cpan.org>

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.

2011-01-05 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.