[Catalyst] Strange DBIC error, only when used in Catalyst

Octavian Rasnita orasnita at gmail.com
Thu Sep 8 09:45:33 GMT 2011


Hi all,

I have the following action:

sub top : Local {
    my ( $self, $c ) =3D @_;

    my $top =3D $c->model( 'Intra::User' )->search_rs({
        'clients.id' =3D> {'!=3D' =3D> undef},
}, {
        join =3D> 'clients',
        prefetch =3D> 'clients',
        select =3D> [ 'id', 'username', 'first_name', 'last_name', {count =
=3D> 'clients.id'} ],
        as =3D> [ 'id', 'username', 'first_name', 'last_name', 'nr_clienti'=
 ],
        group_by =3D> [ 'username' ],
        order_by =3D> [ {-desc =3D> 'nr_clienti'}, {-asc =3D> 'me.last_name=
'} ],
    });

my $nr_contacts =3D $top->count;
}

When I access this action on the web, Catalyst displays the following error:

DBIx::Class::ResultSet::count(): No such relationship clients on User at E:=
/web/TB2/script/../lib/TB/Controller/Clienti.pm line 255

But the Result class User.pm does have the clients relation:

package TB::Schema::Result::User;
...
__PACKAGE__->has_many( "clients", "TB::Schema::Result::Client", { "foreign.=
user_id" =3D> "self.id" }, {} );

And if I use the same code outside Catalyst, it works fine and it prints th=
e result:

use strict;
use lib 'lib';
use TB::Schema;

my $schema =3D TB::Schema->connect( 'dbi:mysql:database=3Dintranet;host=3D1=
0.50.28.70', 'user', 'pass');

    my $top =3D $schema->resultset( 'User' )->search_rs({
        'clients.id' =3D> {'!=3D' =3D> undef},
}, {
        join =3D> 'clients',
        prefetch =3D> 'clients',
        select =3D> [ 'id', 'username', 'first_name', 'last_name', {count =
=3D> 'clients.id'} ],
        as =3D> [ 'id', 'username', 'first_name', 'last_name', 'nr_clienti'=
 ],
        group_by =3D> [ 'username' ],
        order_by =3D> [ {-desc =3D> 'nr_clienti'}, {-asc =3D> 'me.last_name=
'} ],
    });

my $nr_contacts =3D $top->count;

print $nr_contacts;


The model "Intra::User" is the "TB::Schema::User" class as can be seen in t=
he following configuration of the app:

'Model::Intra' =3D> {
schema_class =3D> 'TB::Schema',
connect_info =3D> {
dsn =3D> 'dbi:mysql:database=3Dintranet;host=3D10.50.28.70',
user =3D> 'user',
password =3D> 'pass',
},
},


There are no other errors reported, but just a warning which I think that h=
as nothing to do with that error generated by the Catalyst app:
Class::C3::Componentised::load_components(): Use of DBIx::Class::UTF8Column=
s is strongly discouraged. See documentation of DBIx::Class::UTF8Columns fo=
r more info

Thanks.

--Octavian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110908/0bb98=
853/attachment.htm


More information about the Catalyst mailing list