From: Rafael Kitover Date: Tue, 5 Jul 2011 08:00:05 +0000 (-0400) Subject: sort relationships X-Git-Tag: 0.07011~70 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b33d594954411e85714d4c09be6ba417043b3986;hp=c55ca1943efc83215f21870ecbb6e03a9a63c25f;p=dbsrgits%2FDBIx-Class-Schema-Loader.git sort relationships --- diff --git a/Changes b/Changes index 1fd64b5..bc34c3d 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - sort relationships so they always come out in the same order - add rel_name_map option - fix the decimal data type for MS Access over ODBC - fix enum/set detection for MySQL (RT#68717) diff --git a/TODO b/TODO index c9fcc1e..39b8bb4 100644 --- a/TODO +++ b/TODO @@ -42,6 +42,7 @@ - add result_roles and schema_roles for use with use_moose=1 - generate Schema/ResultBase.pm and Schema/ResultSetBase.pm - remove additional warnings skip in t/22dump.t for ActivePerl on Win32 + - make 23dumpmore.t auto cleanup and remove dump warnings - Relationships - Re-scan relations/tables after initial relation setup to find diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 622be52..eba2832 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -2172,9 +2172,13 @@ sub _load_relationships { my $rel_stmts = $self->_relbuilder->generate_code(\@tables); foreach my $src_class (sort keys %$rel_stmts) { - my $src_stmts = $rel_stmts->{$src_class}; - foreach my $stmt (@$src_stmts) { - $self->_dbic_stmt($src_class,$stmt->{method},@{$stmt->{args}}); + # sort by rel name + my @src_stmts = map $_->[1], + sort { $a->[0] cmp $b->[0] } + map [ $_->{args}[0], $_ ], @{ $rel_stmts->{$src_class} }; + + foreach my $stmt (@src_stmts) { + $self->_dbic_stmt($src_class,$stmt->{method}, @{$stmt->{args}}); } } } diff --git a/t/23dumpmore.t b/t/23dumpmore.t index 747aa9a..1189104 100644 --- a/t/23dumpmore.t +++ b/t/23dumpmore.t @@ -98,6 +98,23 @@ $t->dump_test( $t->cleanup; +# test that rels are sorted +$t->dump_test( + classname => 'DBICTest::Schema::_sorted_rels', + test_db_class => 'make_dbictest_db_with_unique', + warnings => [ + qr/Dumping manual schema for DBICTest::Schema::_sorted_rels to directory /, + qr/Schema dump completed/, + ], + regexes => { + Baz => [ + qr/->might_have\(\n "quux".*->belongs_to\(\n "station_visited"/s, + ], + } +); + +$t->cleanup; + # test naming => { monikers => 'plural' } $t->dump_test( classname => 'DBICTest::Schema::_plural_monikers',