[Catalyst] Nonsensical Problem with DBIx ResultSet
Jeff Albert
jralbert at uvic.ca
Thu Jul 8 16:02:11 GMT 2010
Some of your users have sessions, and thus will have a row or rows in the r=
elated =91session=92 resultset =96 but some don=92t. When you attempt to ac=
cess $user->session->client->clientname, you=92re assuming that $user->sess=
ion is defined =96 but in the case of a user row with no related session ro=
w, $user->session won=92t be defined, and you=92ll raise the error you desc=
ribed when you attempt to access the methods of that resultset. Do a quick =
defined() test on $user->session before you try to use its methods, and you=
=92ll be good to go. Hope that helps!
Cheers,
Jeff Albert
From: Kyle Hall [mailto:kyle.m.hall at gmail.com]
Sent: Thursday, July 08, 2010 7:57 AM
To: catalyst at lists.scsys.co.uk
Subject: [Catalyst] Nonsensical Problem with DBIx ResultSet
Hello all,
I'm the developer of a FOSS kiosk management system, Libki. I'm in the ea=
rly stages of a complete rewrite using Catalyst for the web-based administr=
ation interface. This is my first time using Catalyst, but I'm very excited=
by the possibilities! I'm having a very strange issue with my resultsets. =
For example, I have three tables, a users table, a clients table, and a ses=
sions table that connects the user to a client.
I grab my users from the database, with any session/client data if the user=
is currently logged in to a client kiosk. I am prefetching the session and=
client table data.
my $user_rs =3D $c->model('DB::User')->search( {}, { prefetch =3D> { sessio=
n =3D> 'client' } } );
Now I want to loop through it.
my $row =3D 0;
my @row_data;
while ( my $user =3D $user_rs->next() ) {
my $user_id =3D $user->id;
warn $user->session->client->clientname;
my $single_row =3D {
cell =3D> [
$user->id,
$user->username,
$user->minutes,
$user->status,
$user->is_troublemaker,
$user->session->client->clientname;
]
};
push( @row_data, $single_row );
}
Now, if I try to access any of the other tables, I get an error:
[error] Caught exception in LibkiServer::Controller::Admin::REST->users "Ca=
n't call method "client" on an undefined value at /home/libki/LibkiServer/s=
cript/../lib/LibkiServer/Controller/Admin/REST.pm line 40."
I don't know why I get this error, but the really crazy part is *the warn s=
till works*:
Client Name: testclient1 at /home/libki/LibkiServer/script/../lib/LibkiServ=
er/Controller/Admin/REST.pm line 40.
If anyone can help me out, I'd be eternally grateful.
Thanks,
Kyle
http://www.kylehall.info
Mill Run Technology Solutions ( http://millruntech.com )
Crawford County Federated Library System ( http://www.ccfls.org )
Meadville Public Library ( http://www.meadvillelibrary.org )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100708/528ae=
187/attachment.htm
More information about the Catalyst
mailing list