[Catalyst] DBIx::Class newbish count problems

Dave C skinnydill at gmail.com
Thu Jan 19 01:16:56 CET 2006


I'm attempting to add a GUI using Catalyst to an existing (crappy) DB
structure.  Because of this, I had to disable DBIx::Class::Loader
relationships.  I have 2 tables that I'm attempting to set up relationships
between manually:

package VhostStats::Model::DBIC::Vhosts;

use strict;
use warnings;
use base 'DBIx::Class::Core';

__PACKAGE__->table('vhosts');
__PACKAGE__->add_columns(qw/vid hostname/);
__PACKAGE__->set_primary_key('vid');
__PACKAGE__->has_many(users => 'VhostStats::Model::DBIC::Users', 'vid');

1;

package VhostStats::Model::DBIC::Users;

use strict;
use warnings;
use base 'DBIx::Class::Core';

__PACKAGE__->table('users');
__PACKAGE__->add_columns(qw/uid vid username/);
__PACKAGE__->set_primary_key('uid');
__PACKAGE__->belongs_to('vid' => 'VhostStats::Model::DBIC::Vhosts');

__PACKAGE__->has_one(vid => 'VhostStats::Model::DBIC::Vhosts');

1;

My problem comes when I attempt to get the total number of users on each
given Vhost.  I'm trying to do something such as:

[% FOR vhost IN vhosts %]
<tr><td>vhost.hostname</td><td>vhost.users.count</td></tr>
[% END %]

However, vhost.users successfully returns all rows but
vhost.users.countreturns nothing.  If
vhost.count works, shouldn't vhost.users.count by following the
relationship?  Currently, I'm just looping through vhost.users manually but
that seems too hackish.

Any help would be appreciated.

dave.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060118/5282cbb1/attachment-0001.htm


More information about the Catalyst mailing list