[Dbix-class] Problems getting prefetch to work..
Tim Watson
tiwatson at gmail.com
Sat Jun 24 16:50:03 CEST 2006
I am probably missing something simple here, but I can't see it.
I am having trouble getting any prefetching to work, in my own code or
in the example code linked here:
http://search.cpan.org/~jrobinson/DBIx-Class-0.06003/lib/DBIx/Class/Manual/Example.pod
With the example, only changing the DB type to be mysql and my
login... I get an sql error, the JOIN section is not working
properly....
SELECT me.trackid, me.cd, me.title, cd.cdid, cd.artist, cd.title
FROM track me JOIN cd cd ON ( cd.cdid = me.cd )
WHERE ( cd.title = ? )
In my own code... equally as simple..
-----------
package Db::Schema::User;
use strict;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto Core/); # for example
__PACKAGE__->table('user');
__PACKAGE__->add_columns(qw/ username password /);
__PACKAGE__->set_primary_key('username');
__PACKAGE__->has_many(user_session => 'Db::Schema::Session', 'username');
----------------
package Db::Schema::Session;
use strict;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto Core/); # for example
__PACKAGE__->table('session');
__PACKAGE__->add_columns(qw/sessionid username /);
__PACKAGE__->set_primary_key('sessionid');
__PACKAGE__->belongs_to(username => 'Db::Schema::User');
-----------------
my $rs = $dbh->resultset('Session')->search({ 'session.sessionid' =>
'123456' } ,{ prefetch => 'username' });
my $session = $rs->next;
print "s " . $session->sessionid . "\n";
(prefetching on anything but username gives me a relationship error)
--------
SELECT me.sessionid, me.username, username.username, username.password
FROM session me JOIN user username ON ( username.username =
me.username ) WHERE ( session.sessionid = ? )'
I get the same JOIN errors... Any idea what I am doing wrong ??
--
Tim Watson
More information about the Dbix-class
mailing list