Skip to content

Instantly share code, notes, and snippets.

@arc
Created September 24, 2013 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arc/6688183 to your computer and use it in GitHub Desktop.
Save arc/6688183 to your computer and use it in GitHub Desktop.
Straw-man support for calling table_class/::View in DBIC Schema::Loader. Is this totally insane?
diff --git i/lib/DBIx/Class/Schema/Loader/Base.pm w/lib/DBIx/Class/Schema/Loader/Base.pm
index b37223c..9c1f295 100644
--- i/lib/DBIx/Class/Schema/Loader/Base.pm
+++ w/lib/DBIx/Class/Schema/Loader/Base.pm
@@ -2393,6 +2393,11 @@ sub _make_column_accessor_name {
return $accessor;
}
+sub _table_is_view {
+ #my ($self, $table) = @_;
+ return 0;
+}
+
# Set up metadata (cols, pks, etc)
sub _setup_src_meta {
my ($self, $table) = @_;
@@ -2403,6 +2408,9 @@ sub _setup_src_meta {
my $table_class = $self->classes->{$table->sql_name};
my $table_moniker = $self->monikers->{$table->sql_name};
+ $self->_dbic_stmt($table_class, 'table_class', 'DBIx::Class::ResultSource::View')
+ if $self->_table_is_view($table);
+
$self->_dbic_stmt($table_class, 'table', $table->dbic_name);
my $cols = $self->_table_columns($table);
diff --git i/lib/DBIx/Class/Schema/Loader/DBI.pm w/lib/DBIx/Class/Schema/Loader/DBI.pm
index d3ce9b7..853ac12 100644
--- i/lib/DBIx/Class/Schema/Loader/DBI.pm
+++ w/lib/DBIx/Class/Schema/Loader/DBI.pm
@@ -636,6 +636,15 @@ sub dbh {
return $self->schema->storage->dbh;
}
+sub _table_is_view {
+ my ($self, $table) = @_;
+ my $sth = $self->dbh->table_info(undef, $table->schema, $table->name, 'VIEW');
+ for my $rel (@{ $sth->fetchall_arrayref({}) }) {
+ return 1;
+ }
+ return 0;
+}
+
=head1 SEE ALSO
L<DBIx::Class::Schema::Loader>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment