[Dbix-class] using load_namespaces

Ian Docherty dbix-class at iandocherty.com
Thu Sep 27 15:13:02 GMT 2007


I started this conversation on the Catalyst group, but it now is more 
appropriate to continue on this group.

I previously used load_classes and my ResultSet classes were in the 
MyApp::Schema namespace and MyApp::Schema::Demo would be the result-set 
for the Demo table.

If I understand it correctly and I want to have both ResultSet and 
Result classes I should use the load_namespaces which gives me the 
namespaces MyApp::Schema::Result::Demo and MyApp::Schema::ResultSet::Demo

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.

Here is my code.

#### test.pl
use strict;
use warnings;

use MyApp::Schema;

my $schema = 
MyApp::Schema->connect('DBI:mysql:host=localhost;database=vertex_icydee', 
'sprint', 'secret', { AutoCommit => 1}, {quote_char => q{`}, name_sep => 
q{.}});

my $demo_rs = $schema->resultset('Demo');

my $demo = $demo_rs->create({name => 'fred', value => 1});
$demo->do_something;

1;

#####
package MyApp::Schema;

use strict;
use warnings;

use base qw(DBIx::Class::Schema);

__PACKAGE__->load_namespaces;

1;

#####
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;




More information about the DBIx-Class mailing list