Subject: | MethodMaker naming errors |
We are working with a huge MySQL database (about 300 tables and more than 600 foreign key relationships). All keys ar "readable", i.e. of type char or varchar. In addition, we are using multi-column keys for some exceptional cases. We have support for 12 languages, and therefore many relationships to our "i18n" table; some tables have two or three foreign key columns to the "i18n" table.
The use of MethodMaker (all methods) generates a very long list of naming errors. Attached You will find our patch for a correct name handling.
=== MethodMaker.pm
==================================================================
--- MethodMaker.pm (revision 6)
+++ MethodMaker.pm (local)
@@ -854,30 +856,49 @@
return $p{table}->name if $p{type} eq 'table';
- return $p{column}->name if $p{type} eq 'table_column';
+ return lc($p{column}->name) if $p{type} eq 'table_column';
- return $p{column}->name if $p{type} eq 'row_column';
+ return lc($p{column}->name) if $p{type} eq 'row_column';
if ( $p{type} eq 'foreign_key' )
{
- return $p{foreign_key}->table_to->name;
+
+ return $p{foreign_key}->table_to->name
+ if lc($p{foreign_key}->columns_to->name) eq
+ lc($p{foreign_key}->columns_from->name);
+
+ if (join("",$p{foreign_key}->cardinality) eq 'n1') {
+ return $p{foreign_key}->table_to->name.
+ '_'.$p{foreign_key}->columns_from->name;
+ } else {
+ return $p{foreign_key}->table_to->name.'_'.
+ lc($p{foreign_key}->columns_to->name);
+ }
}
if ( $p{type} eq 'linking_table' )
{
- my $method = $p{foreign_key}->table_to->name;
- my $tname = $p{foreign_key}->table_from->name;
- $method =~ s/^$tname\_?//;
- $method =~ s/_?$tname$//;
+ # Conflicts with foreign key name; hence use foreign_key_2
+ my $method = "link".$p{foreign_key_2}->table_to->name;
+ #my $tname = $p{foreign_key}->table_from->name;
+ #$method =~ s/^$tname\_?//;
+ #$method =~ s/_?$tname$//;
return $method;
}
+ if ($p{type} eq 'lookup_columns') {
+ if ($p{foreign_key}->columns_from->name ne
+ $p{foreign_key}->columns_to->name) {
+ return $p{foreign_key}->table_to->name.'_'.
+ $p{foreign_key}->columns_from->name.'_'.
+ lc($p{column}->name);
+ } else {
+ return $p{foreign_key}->table_to->name.'_'.lc($p{column}->name);
+ }
+ }
- return join '_', map { lc $_->name } $p{foreign_key}->table_to, $p{column}
- if $p{type} eq 'lookup_columns';
+ return lc($p{column}->name) if $p{type} eq 'lookup_columns';
- return $p{column}->name if $p{type} eq 'lookup_columns';
-
return $p{parent} ? 'parent' : 'children'
if $p{type} eq 'self_relation';