in reply to DBIx::Class problem

Adding __PACKAGE__->table('CustomTest'); seemed to help.
package TA::CP::DB::Schema::Result::CustomTest; use strict; use warnings; use base qw/DBIx::Class::Core/; __PACKAGE__->table_class('DBIx::Class::ResultSource::View'); __PACKAGE__->table('CustomTest'); __PACKAGE__->result_source_instance->is_virtual(1); __PACKAGE__->result_source_instance->view_definition(\"select 2*2");

Replies are listed 'Best First'.
Re^2: DBIx::Class problem
by morgon (Priest) on Jan 26, 2011 at 02:12 UTC
    Thanks.

    So even for queries that don't use a table you have to set a table (any dummy value will do).

    Here a complete working example:

    package TA::CP::DB::Schema::Result::CustomTest; use strict; use warnings; use base qw/DBIx::Class::Core/; __PACKAGE__->table_class('DBIx::Class::ResultSource::View'); __PACKAGE__->table('DUMMY'); __PACKAGE__->add_columns("x"); __PACKAGE__->result_source_instance->is_virtual(1); __PACKAGE__->result_source_instance->view_definition("select 2*2 as x" +);
    This can then be used as usual:
    my ($res) = $schema->resultset("CustomTest")->all; print $res->x; # prints 4
    </c>