From: Tom Bloor Date: Tue, 19 May 2015 14:47:47 +0000 (+0000) Subject: Temporary fix using SQL::Translator X-Git-Tag: v1.001_031~2^2~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-Fixtures.git;a=commitdiff_plain;h=534c9101db43c5a34164ceb17aac9324e3864930 Temporary fix using SQL::Translator --- diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm index 36f8d0e..8b41008 100644 --- a/lib/DBIx/Class/Fixtures.pm +++ b/lib/DBIx/Class/Fixtures.pm @@ -1355,7 +1355,31 @@ sub populate { $schema->storage->txn_do(sub { $schema->storage->with_deferred_fk_checks(sub { - foreach my $source (sort $schema->sources) { + + use SQL::Translator; + + # parse the schema with SQL::Translator + my $sqlt = SQL::Translator->new( + parser => 'SQL::Translator::Parser::DBIx::Class', + parser_args => { + dbic_schema => $schema, + }, + ); + $sqlt->translate; + + # pull out the SQLT Schema, and create a hash with the correct order for tables + my $sqlt_schema = $sqlt->schema; + my %table_order = map +($_->name => $_->order - 1), $sqlt_schema->get_tables; + + # create an array using the correct table order + my @sorted_source_names; + for my $source ( $schema->sources ) { + next unless $source; # somehow theres an undef one + my $table = $schema->source( $source )->name; + $sorted_source_names[ $table_order{ $table } ] = $source; + } + + foreach my $source (@sorted_source_names) { $self->msg("- adding " . $source); my $rs = $schema->resultset($source); my $source_dir = io->catdir($tmp_fixture_dir, $self->_name_for_source($rs->result_source));