[Dbix-class] [Fwd: Re: [Catalyst] DBIx::Class newbish count problems]

Will Hawes info at whawes.co.uk
Thu Jan 19 23:44:49 CET 2006


Forwarded to list...

-------- Original Message --------
Subject: 	Re: [Catalyst] DBIx::Class newbish count problems
Date: 	Thu, 19 Jan 2006 17:12:36 -0500
From: 	Dave C <skinnydill at gmail.com>
To: 	info at whawes.co.uk
References:
<8924227e0601181616s2fd9d857l4af09325d999b93 at mail.gmail.com>
<43CF5525.4090001 at whawes.co.uk>



On 1/19/06, *Will Hawes* <info at whawes.co.uk <mailto:info at whawes.co.uk>>
wrote:



     1) What version of DBIx::Class are you using?


0.04001

     2) Why do you have both belongs_to and has_one relationships defined
     from Users to Vhosts? Try removing the has_one and see if that 
makes any
     difference.


Oops.  That was left over from trying to see if there was any difference
between     the two.  I removed the has_one, and there was no change.

     If not, what does dumping vhost.users give you? E.g.:

     [% USE Dumper; Dumper.dump (vhost.users) %]


It gives me (as expected), an array of VhostStats::Model::Users objects
for all users that match vid.  When I try and dump vhost.users.count,
nothing is returned.

     Incidentally, it can be also helpful to run problem code outside of TT
     while you debug it. IME warnings/errors that can help determine a
     problem do not always make it to your template's output.


Good suggestion.  I set up a simple test senario outside of Catalyst,
and I'm able to list the number of matching rows with vhost.users.count
successfully.  I tried to duplicate that exact setup, but am still
having the same problems.

This works.  Even with only the has_many in MyApp::DBIC::Vhosts.

package MyApp::DBIC;

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

__PACKAGE__->load_components(qw/PK::Auto::MySQL Core DB/);
__PACKAGE__->connection('dbi:mysql:vhoststats;host= 127.0.0.1
<http://127.0.0.1>', '', '');

1;

package MyApp::DBIC::Users;

use strict;
use warnings;
use base 'MyApp::DBIC';

__PACKAGE__->table('users');
__PACKAGE__->add_columns(qw/uid vid username aid/);
__PACKAGE__->set_primary_key('uid');

1;

package MyApp::DBIC::Vhosts;

use strict;
use warnings;
use base 'MyApp::DBIC';

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

1;


And here's what I've tried to replicate in Catalyst.  The only major
difference I saw was that I was inheriting from Catalyst::Model::DBIC
originally.  I tried to change that to DBIx::Class and still no luck:

package VhostStats::Model::DBIC;

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

__PACKAGE__->load_components(qw/PK::Auto::MySQL Core DB/);
__PACKAGE__->connection('dbi:mysql:vhoststats;host= 127.0.0.1
<http://127.0.0.1>', '', '');


1;

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

use strict;
use warnings;
use base 'VhostStats::Model::DBIC';

__PACKAGE__->table('users');
__PACKAGE__->add_columns(qw/uid vid username aid/);
__PACKAGE__->set_primary_key('uid');

1;

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

use strict;
use warnings;
use base 'VhostStats::Model::DBIC';

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

1;


Any idears?  Thanks for your help so far!

dave.



More information about the Dbix-class mailing list