[Dbix-class] A problem with Postgres schemas

Kevin Esteb kesteb at wsipc.org
Thu Dec 28 21:31:17 GMT 2006


Ok, I made that change and am now getting this error:

 DBIx::Class::Schema::resultset(): Can't find source for Master at
test9.pl line 28

Which seems to indicate that the load_classes() may not be working
correctly. Since when I do this:

__PACKAGE__->load_classes('Master");

I get this error:

Can't locate object method "source_name" via package
"Test::Schema::Master" at /wise/lib/perl5/DBIx/Class/Schema.pm line 280.

And for the question of why I used "analog.master" instead of "Master",
well straight DBI uses that syntax and Class::DBI didn't complain when I
used that syntax. So, just a newbie mistake.


-----Original Message-----
From: John Napiorkowski [mailto:jjn1056 at yahoo.com] 
Sent: Thursday, December 28, 2006 1:15 PM
To: dbix-class at lists.rawmode.org
Subject: Re: [Dbix-class] A problem with Postgres schemas


--- Kevin Esteb <kesteb at wsipc.org> wrote:

> I new to DBIx::Class, so please bear with me. 
> 
> I am running RHEL4 and have a postgres database with a schema named 
> "analog". The DBIx::Class modules are the latest and greatest from 
> CPAN, so is the DBD and the DBI for postgres. When I run the below 
> code, I get this error:
> 
> DBIx::Class::Schema::resultset(): Can't find source for analog.master 
> at test9.pl line 28
> 
> What is the proper way to access another database schema within 
> postgres.
> 
> Thanks
> 
> 
> package Test::Schema;
> use base qw/ DBIx::Class::Schema /;
> 
> __PACKAGE__->load_classes();
> 
> 1;
> 
> package Test::Schema::Master;
> use base qw/ DBIx::Class /;
> 
> __PACKAGE__->load_components(qw/ PK::Auto Core /); 
> __PACKAGE__->table('analog.master');
> __PACKAGE__->add_columns(qw/ hostname datetime did /); 
> __PACKAGE__->set_primary_key('hostname');
> 
> 1;
> 
> package Test;
> 
>     my $dsn = 'dbi:Pg:dbname=monitor';
>     my $username = 'postgres';
>     my $password = '';
>     my $params = {RaiseError => 1, AutoCommit => 0};
> 
>     eval {
> 
>         my $schema = Test::Schema->connect($dsn, $username, $password,

> $params);
>         my @masters =
> $schema->resultset('analog.master')->search();
> 
>         foreach my $master (@masters) {
> 
>            print "$master->hostname,
> $master->datetime, $master->did\n";
> 
>        }
> 
>    }; if ($@) { print "$@\n"; }
> 
> 1;

I also use Postgres with schemas; if your schema name is not the default
schema you need to use:

__PACKAGE__->table('analog.master');

which you did, but you don't do 'schema.table' for the
resultset:

$schema->resultset('analog.master')->search()

because the resultset is based on the class:

package Test::Schema::Master;

Try:

$schema->resultset('Master')->search();

and if everything else is right it should work.  If not let me know, I
can share with you my setup.

Actually it's just convention to have the Schema name and the table name
the same, you could do otherwise from what I understand (although I
haven't tried it :)

--John

> 
> _______________________________________________
> List:
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN:
>
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive:
>
http://www.mail-archive.com/dbix-class@lists.rawmode.org/
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive:
http://www.mail-archive.com/dbix-class@lists.rawmode.org/



More information about the Dbix-class mailing list