From: Rafael Kitover Date: Thu, 10 Jun 2010 05:29:34 +0000 (-0400) Subject: fix bug in qualify_objects that would add schema to relnames X-Git-Tag: 0.07001~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=414c61a02b22a17b8dbdad49e4e47d4cee1c3981;p=dbsrgits%2FDBIx-Class-Schema-Loader.git fix bug in qualify_objects that would add schema to relnames --- diff --git a/Changes b/Changes index 353d295..a2ae8a1 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - fix bug in qualify_objects that would add schema to relnames + - better type info for Informix, except for DATETIME precision and + INTERVAL support - better type info for DB2 - fix some newly-introduced test bugs diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm index a0de181..e3475dd 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm @@ -213,9 +213,26 @@ sub _remote_attrs { return $attrs; } +sub _sanitize_name { + my ($self, $name) = @_; + + if (ref $name) { + # scalar ref for weird table name (like one containing a '.') + ($name = $$name) =~ s/\W+/_/g; + } + else { + # remove 'schema.' prefix if any + $name =~ s/^[^.]+\.//; + } + + return $name; +} + sub _normalize_name { my ($self, $name) = @_; + $name = $self->_sanitize_name($name); + my @words = split_name $name; return join '_', map lc, @words; diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_06.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_06.pm index 92a96c5..d0bfb78 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_06.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_06.pm @@ -12,6 +12,8 @@ our $VERSION = '0.07001'; sub _normalize_name { my ($self, $name) = @_; + $name = $self->_sanitize_name($name); + return lc $name; } diff --git a/t/23dumpmore.t b/t/23dumpmore.t index c02c279..ea5fd6b 100644 --- a/t/23dumpmore.t +++ b/t/23dumpmore.t @@ -368,6 +368,8 @@ do_dump_test( regexes => { 'Result/Foo' => [ qr/^\Q__PACKAGE__->table("foo_schema.foo");\E/m, + # the has_many relname should not have the schema in it! + qr/^__PACKAGE__->has_many\(\n "bars"/m, ], }, );