From: Matt S Trout Date: Tue, 18 Aug 2009 03:05:37 +0000 (+0000) Subject: dependency for views X-Git-Tag: v0.08124~114^2~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=943538a0c95dadb185600979901b76c404445b72;p=dbsrgits%2FDBIx-Class.git dependency for views --- diff --git a/lib/DBIx/Class/ResultSource/View.pm b/lib/DBIx/Class/ResultSource/View.pm index d992c71..2779492 100644 --- a/lib/DBIx/Class/ResultSource/View.pm +++ b/lib/DBIx/Class/ResultSource/View.pm @@ -8,9 +8,15 @@ use DBIx::Class::ResultSet; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/ResultSource/); __PACKAGE__->mk_group_accessors( - 'simple' => qw(is_virtual view_definition) + 'simple' => qw(is_virtual view_definition depends_on) ); +sub new { + my $new = shift->next::method(@_); + $new->{depends_on} = { %{$new->{depends_on}||{}} }; + return $new; +} + =head1 NAME DBIx::Class::ResultSource::View - ResultSource object representing a view diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 2ee47d5..9fff6b4 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -274,9 +274,16 @@ EOW } my %views; - foreach my $moniker (sort @view_monikers) + my @view_sources = + sort { + (exists $a->depends_on->{$b->source_name} ? 1 : 0) + <=> + (exists $b->depends_on->{$a->source_name} ? 1 : 0) + } + map { $dbicschema->source($_) } @view_monikers; + + foreach my $source (@view_sources) { - my $source = $dbicschema->source($moniker); my $view_name = $source->name; # FIXME - this isn't the right way to do it, but sqlt does not