[Dbix-class] using load_namespaces
Matt S Trout
dbix-class at trout.me.uk
Thu Sep 27 21:45:47 GMT 2007
On Thu, Sep 27, 2007 at 11:51:58AM -0400, Jason Gottshall wrote:
> 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.
Close. The Result class has a 'result_source_instance' class data entry
that's registered with the schema when it's loaded; this object is a
ResultSource and represents the table.
Things like add_columns, set_primary_key etc. both create methods on the
result class (accessors etc.) and add the relevant information to the
ResultSource (table) object.
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
More information about the DBIx-Class
mailing list