Hi all,

I have the following action:

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

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

my $nr_contacts = $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" => "self.id" }, {} );

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

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

my $schema = TB::Schema->connect( 
'dbi:mysql:database=intranet;host=10.50.28.70', 'user', 'pass');

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

my $nr_contacts = $top->count;

print $nr_contacts;


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

'Model::Intra' => {
schema_class => 'TB::Schema',
connect_info => {
dsn => 'dbi:mysql:database=intranet;host=10.50.28.70',
user => 'user',
password => 'pass',
},
},


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

Thanks.

--Octavian
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to