[Dbix-class] Problem overriding connection method from Schema module

Emmanuel Quevillon tuco at pasteur.fr
Mon Aug 24 07:23:06 GMT 2009


Byron Young wrote:
> Emmanuel Quevillon wrote on 2009-08-21:
>> sub connection {
>>
>>     my ($self, @rest) = @_;
>>     $self->next::method(@rest);
>>     
>>     $self->driver_name($self->handler()->{Driver}->{Name});
>>
>> }
>> # You can replace this text with custom content, and it will be
>> preserved on regeneration
>>
>> 1;
>>
> 
> Hey Emmanuel,
> 
> connection() must return the schema object (which will be returned by $self->next::method(@rest)).  In this case it will actually return the driver name string instead, which explains why the interpreter chokes when it tries to call the resultset() method on a string, as in your error below.
> 


Hi Byron,

Thanks to pointing me to this. It makes a lot of sense! I fixed it
and it works like a charm both from my scripts and from my Catalyst App.

>> my $schema =
>> Schema::MyAppDB->connect('dib:Pg:dbname=test','test','pass'); my $a =
>> $schema->resultset("Public"); ....
>>
>>
>> I get the following error
>>
>> Can't locate object method "resultset" via package "Pg" (perhaps you
>> forgot to load "Pg"?) at ./test.pl line 7.
> 
> The Catalyst cookbook section is incorrect - it would be great for you to supply a doc patch to the catalyst list so other people don't run into this as well.
> 
> Byron
> 
> 
Emmanuel

-- 
-------------------------
Emmanuel Quevillon
Biological Software and Databases Group
Institut Pasteur
+33 1 44 38 95 98
tuco at_ pasteur dot fr
-------------------------



More information about the DBIx-Class mailing list