From: Rafael Kitover Date: Mon, 22 Mar 2010 23:18:39 +0000 (-0400) Subject: check for table moniker clashes (patch from ribasushi) X-Git-Tag: 0.06000~34 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-Schema-Loader.git;a=commitdiff_plain;h=27305cc132ba6ec1543771c1842dceeb41956063 check for table moniker clashes (patch from ribasushi) --- diff --git a/Changes b/Changes index 1200e1f..0119f2c 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - croak if several tables reduce to an identical moniker (ribasushi) - better type info for Sybase ASE - better type info for Pg: sets sequence for serials, handles numerics without precision diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index dbfa47f..e0a42fa 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -932,6 +932,34 @@ sub _load_tables { } $self->_make_src_class($_) for @tables; + + + # sanity-check for moniker clashes + my $inverse_moniker_idx; + for (keys %{$self->monikers}) { + push @{$inverse_moniker_idx->{$self->monikers->{$_}}}, $_; + } + + my @clashes; + for (keys %$inverse_moniker_idx) { + my $tables = $inverse_moniker_idx->{$_}; + if (@$tables > 1) { + push @clashes, sprintf ("tables %s reduced to the same source moniker '%s'", + join (', ', map { "'$_'" } @$tables), + $_, + ); + } + } + + if (@clashes) { + die 'Unable to load schema - chosen moniker/class naming style results in moniker clashes. ' + . 'Either change the naming style, or supply an explicit moniker_map: ' + . join ('; ', @clashes) + . "\n" + ; + } + + $self->_setup_src_meta($_) for @tables; if(!$self->skip_relationships) {