NAME

DBIx::Class::LookupColumn::Auto - A dbic component for installing LookupColumn relations on a whole schema at once.

SYNOPSIS

 package MySchema; 

 __PACKAGE__->load_components( qw/LookupColumn::Auto/ );

 my @tables = __PACKAGE__->sources; # get all table names 
 
 my @candidates =  grep { ! /Type$/ } @tables;  # tables that do NOT end with Type
 my @lookups =  grep {  /Type$/ } @tables;      # tables that DO end with Type == the Lookup Tables !

 __PACKAGE__->add_lookups(
	targets => \@candidates, 
	lookups => \@lookups,
	
	# function that will generate the relation names: here we build it from the Lookup Table
	relation_name_builder => sub{
		my ( $class, %args) = @_;
		$args{lookup} =~ /^(.+)Type$/; # remove the end (Type) from the Lookup table name
		lc( $1 );
	},
	# function that gives the name of the column that holds the definitions/values: here it is always 'name'
	lookup_field_name_builder => sub { 'name' } 
 );

DESCRIPTION

This component automates the addition of the Lookup (see "Lookup Tables" in DBIx::Class::LookupColumn) relations to a whole set of tables.

Given a set of potential target tables (the tables on which to add the Lookup relations), and a set of Lookup tables, the component will select all the belongs_to relations defined in the target tables pointing to a Lookup table present in the set and add a Lookup relation automatically.

It is also possible to add accessors manuall by doing a copy/paste of the code diplayed with the verbose option (See add_lookups).

METHODS

add_lookups

__PACKAGE__->add_lookups( { targets => [], lookups => [], relation_name_builder? => sub {}, lookup_field_name_builder? => sub {}, verbose? => boolean } )

This will iterate through the set of targets tables on all belongs_to relations pointing to a table included in lookups and add a corresponding relation.

Arguments (hash keys) :

targets

An ArrayRef of the names of the tables on which to detect and install the Lookup relations.

lookups

An ArrayRef of the names of the Lookup tables.

relation_name_builder?

Optional. FuncRef for building the accessors base name. By default the name of the Lookup table in small caps. Arguments (hash keys) : { target => ?, lookup => ?, foreign_key => ? }.

lookup_field_name_builder?

Optional. FuncRef for specifying the concerned column name in the Lookup table. By default the first varchar type column in the Lookup table.

verbose?

Optional. Boolean for displaying the code for adding a Lookup relation. Copy/paste it the right place of your code. By default set to false, then non-verbose.

AUTHORS

Karl Forner <karl.forner@gmail.com>

Thomas Rubattel <rubattel@cpan.org>

BUGS

Please report any bugs or feature requests to bug-dbix-class-lookupcolumn-auto at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-LookupColumn-Auto. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc DBIx::Class::LookupColumn::Auto

You can also look for information at:

LICENCE AND COPYRIGHT

Copyright 2012 Karl Forner and Thomas Rubattel, All Rights Reserved.

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