[Dbix-class] using load_namespaces
Jason Gottshall
jgottshall at capwiz.com
Thu Sep 27 16:51:58 GMT 2007
Ian Docherty wrote:
> I get the following error. All my classes compile OK.
>
> Can't locate object method "source_name" via package
> "MyApp::Schema::Result::Demo" at
> /usr/lib/perl5/site_perl/5.8.8/DBIx/Class/Schema.pm line 443.
> Compilation failed in require at test.pl line 4.
> BEGIN failed--compilation aborted at test.pl line 4.
[snip]
> package MyApp::Schema::ResultSet::Demo;
>
> use strict;
> use warnings;
>
> use base qw(DBIx::Class);
>
> __PACKAGE__->load_components(qw(PK::Auto Core));
> __PACKAGE__->table('demo');
> __PACKAGE__->add_columns(qw(id creator owner name value state));
> __PACKAGE__->set_primary_key('id');
>
> 1;
>
> #####
> package MyApp::Schema::Result::Demo;
> use strict;
> use warnings;
>
> sub do_something {
> my ($self) = @_;
>
> $self->state('pending');
> $self->update;
> }
>
> 1;
Your ResultSet and Result classes are reversed. The "Result" is also
known as the "source", and describes the table and its relationships;
it's also where you can put custom methods for individual rows that you
retrieve. The "ResultSet" is where you put methods for operating on
queries as a whole.
HTH,
Jason
More information about the DBIx-Class
mailing list