morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am trying to use a custom resultset and I am getting this error:

DBIx::Class::Schema::throw_exception(): Can't locate object method "result_source_instance" via package ...

Here is what the documentation says for such cases:

Can't locate method result_source_instance For some reason the table class in question didn't load fully, so the +ResultSource object for it hasn't been created. Debug this class in i +solation, then try loading the full schema again.
My class is as simple as it can be (bascially a copy from the Cookbook-example) and is syntactically valid.

So how can I "Debug this class in isolation"?

What does that mean? What can I do to isolate the problem (I assume the Cookbook examples are tested or is it possible that they don't work anymore?).

Many thanks!

Update:

Here my class:

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__->result_source_instance->is_virtual(1); __PACKAGE__->result_source_instance->view_definition(\"select 2*2");

Replies are listed 'Best First'.
Re: DBIx::Class problem
by Khen1950fx (Canon) on Jan 25, 2011 at 00:18 UTC
    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");
      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>