|
NAMEDBICx::MapMaker - automatically create a DBIx::Class mapping tableVERSIONversion 0.03SYNOPSISA 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 METHODSnewCreate 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".ATTRIBUTESHere are the attributes that you can pass to the constructor:left_class right_classThe class name of the left/right table (the tables that have a m2m relationship between them).Required. left_name right_nameThe column name for the left/right table's primary key in the map table.Required. left_to_map_relation right_to_map_relationThe 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_rightThe 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. tablenameThe name of the created mapping table.Optional. Defaults to "map_"left_name"_"right_name"". (With "foo" and "bar", "map_foo_bar".) AUTHORSJonathan Rockway "<jrockway@cpan.org>"Stevan Little "<stevan.little@iinteractive.com>" Adam Herzog "<adam@adamherzog.com>" COPYRIGHT AND LICENSECopyright 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. AUTHORJonathan Rockway <jrockway@cpan.org>COPYRIGHT AND LICENSEThis 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.
Visit the GSP FreeBSD Man Page Interface. |