[Catalyst] storing a list of items into the session

Guillermo Roditi groditi at gmail.com
Sun Mar 23 21:33:54 GMT 2008


>         $c->session->{mandator} = $c->model('MotsDB::Mandator')->find();
>         $c->session->{mandators} = $c->model('MotsDB::Mandator');

I see two potential problems here

You are trying to store a resultset into the session. I made this same
mistake when I started using catalyst, don't worry. What's happening
is that your object is being serialized in between page views and you
are losing the DB connection there. DBIC allows you to freeze and thaw
objects and restore connections pretty easily, see the POD in
DBIx::Class::Schema for more info. I know that the object you got
using find() appears to work, but relationships will be broken. Either
properly freeze and thaw objects, or fetch them in every request.

Other potential problem
in scalar context  $c->model('MotsDB::Mandator'); which is
functionally equivalent to $schema->resultset('Mandator') returns a
resultset, nor a list.  If you would like to obtain the actual objects
instead of the resultsets use [ $c->model('MotsDB::Mandator') ] or
$c->model('MotsDB::Mandator')->all. The previous creates an arrayref
of all the items and the later returns a list of all the items



-- 
Guillermo Roditi (groditi)



More information about the Catalyst mailing list