From: Jess Robinson Date: Wed, 11 Feb 2009 14:38:08 +0000 (+0000) Subject: Merge 'view_support' into 'views' X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ed899df367fc90a6b30f1e17d0ea4e2bc2e094f6;p=dbsrgits%2FDBIx-Class-Historic.git Merge 'view_support' into 'views' Original code --- ed899df367fc90a6b30f1e17d0ea4e2bc2e094f6 diff --cc lib/SQL/Translator/Parser/DBIx/Class.pm index 2b408e2,63cbf92..835edbb --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@@ -65,8 -65,18 +65,19 @@@ sub parse @monikers = grep { $sources->{$_} } @monikers; } + - foreach my $moniker (sort @monikers) + my(@table_monikers, @view_monikers); + for my $moniker (@monikers){ + my $source = $dbicschema->source($moniker); + next if $source->is_virtual; + if ( $source->isa('DBIx::Class::ResultSource::Table') ) { + push(@table_monikers, $moniker); + } elsif( $source->isa('DBIx::Class::ResultSource::View') ){ + push(@view_monikers, $moniker); + } + } + + foreach my $moniker (sort @table_monikers) { my $source = $dbicschema->source($moniker); @@@ -215,9 -224,31 +226,28 @@@ } } - if ($source->result_class->can('sqlt_deploy_hook')) { - $source->result_class->sqlt_deploy_hook($table); - } + $source->_invoke_sqlt_deploy_hook($table); } + foreach my $moniker (sort @view_monikers) + { + my $source = $dbicschema->source($moniker); + # Skip custom query sources + next if ref($source->name); + + # Its possible to have multiple DBIC source using same table + next if $seen_tables{$source->name}++; + + my $view = $schema->add_view( + name => $source->name, + fields => [ $source->columns ], + $source->view_definition ? ( 'sql' => $source->view_definition ) : () + ); + if ($source->result_class->can('sqlt_deploy_hook')) { + $source->result_class->sqlt_deploy_hook($view); + } + } + - if ($dbicschema->can('sqlt_deploy_hook')) { $dbicschema->sqlt_deploy_hook($schema); }