Merge 'view_support' into 'views'
Jess Robinson [Wed, 11 Feb 2009 14:38:08 +0000 (14:38 +0000)]
Original code

1  2 
lib/SQL/Translator/Parser/DBIx/Class.pm
t/lib/DBICTest/Schema.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);
          
              }
          }
                
 -        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);
      }
Simple merge