[Catalyst] Database schema -- Can't locate object method "new" via package

Jess Robinson castaway at desert-island.demon.co.uk
Fri Jun 16 14:56:39 CEST 2006



On Thu, 15 Jun 2006, Kevin Old wrote:

> On 6/15/06, Sarah Berry <berry.sarah at gmail.com> wrote:
>> I'm trying to learn how to use the database plugins, specifically DBIx. I
>> set up my schemas to load from an existing database (hopefully), and now I
>> want to test it out to see if I did that right. So I put the following lines
>> into a page called dbixdemo.pm, in the "default" function:
>>
>>         my $schema = VieSEB::Schema::SLogDB->new();
>>         my $crazy_attempt =
>> $schema->resultset('SLogDB')->find(14);
>
> Hi Sarah,
>
> Make your calls in Controllers like this:
>
> $c->model("VieSEB::Schema::SLogDB")->new();
> $c->model("VieSEB::Schema::SLogDB")->search();
> $c->model("VieSEB::Schema::SLogDB")->find();
>

Or, more sanely:

my $schema = $c->model("SLogDB");
my $attempt = $schema->resultset('Foo')->find(14);

or even:

my $attempt = $c->model('SLogDB::Foo')->find(14);

You shouldnt need to call ->new, as Catalyst does that for you, and stores 
the result, which you can retrieve using $c->model.

Are there not examples in the Catalyst::Model::DBIC::Schema pod?

Jess




More information about the Catalyst mailing list