"_engine" => 'InnoDB',
});
+=cut
+
+sub is_virtual { 0 }
+
+=pod
+
+=head2 is_virtual
+
+Returns true if the resultsource is a virtual result source. This stub
+method returns false by default, see L<DBIx::Class::ResultSource::View>
+for more information.
+
=head2 add_columns
$table->add_columns(qw/col1 col2 col3/);
--- /dev/null
+package DBIx::Class::ResultSource::View;
+
+use strict;
+use warnings;
+
+use DBIx::Class::ResultSet;
+
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/ResultSource/);
+__PACKAGE__->mk_group_accessors(
+ 'simple' => qw(is_virtual view_definition)
+);
+
+=head1 NAME
+
+DBIx::Class::ResultSource::Table - Table object
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+Table object that inherits from L<DBIx::Class::ResultSource>
+
+=head1 METHODS
+
+=head2 is_virtual
+
+Attribute to declare a view as virtual.
+
+=head2 from
+
+Returns the FROM entry for the table (i.e. the view name)
+or the definition if this is a virtual view.
+
+=cut
+
+sub from {
+ my $self = shift;
+ return \"(${\$self->view_definition})" if $self->is_virtual;
+ return $self->name;
+}
+
+1;
+
+=head1 AUTHORS
+
+Matt S. Trout <mst@shadowcatsystems.co.uk>
+
+With Contributions from:
+
+Guillermo Roditi E<lt>groditi@cpan.orgE<gt>
+
+=head1 LICENSE
+
+You may distribute this code under the same terms as Perl itself.
+
+=cut
+
@monikers = grep { $sources->{$_} } @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 @monikers)
+ foreach my $moniker (sort @table_monikers)
{
my $source = $dbicschema->source($moniker);
}
}
+ 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 ? $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);
}
eval "use DBD::mysql; use SQL::Translator 0.09;";
plan $@
? ( skip_all => 'needs SQL::Translator 0.09 for testing' )
- : ( tests => 99 );
+ : ( tests => 102 );
}
my $schema = DBICTest->init_schema();
#dummy
Track
Tag
+ Year2000CDs
/,
{ 'DBICTest::Schema' => [qw/
LinerNotes
--- /dev/null
+package # hide from PAUSE
+ DBICTest::Schema::Year2000CDs;
+
+use base 'DBIx::Class::Core';
+use DBIx::Class::ResultSource::View;
+
+__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
+
+__PACKAGE__->table('cd');
+__PACKAGE__->result_source_instance->view_definition(
+ "SELECT cdid, artist, title FROM cd WHERE year ='2000'"
+);
+__PACKAGE__->add_columns(
+ 'cdid' => {
+ data_type => 'integer',
+ is_auto_increment => 1,
+ },
+ 'artist' => {
+ data_type => 'integer',
+ },
+ 'title' => {
+ data_type => 'varchar',
+ size => 100,
+ },
+
+);
+__PACKAGE__->set_primary_key('cdid');
+__PACKAGE__->add_unique_constraint([ qw/artist title/ ]);
+
+1;