[Catalyst] List/Scalar Context with TT + DBIC

Christopher H. Laco claco at chrislaco.com
Wed May 31 22:47:56 CEST 2006


Mark Blythe wrote:
> This isn't strictly a Catalyst question, but it involves the
> interaction of two commonly used Catalyst components: TT + DBIC.  I'm
> sure this must be an FAQ, but so far, RTFM and Googling have not
> revealed the answer.
> 
> How can I force scalar context from TT in order to get a DBIC
> ResultSet object back from search() rather than a list of rows?  For
> instance:
> 
> In TT template:
> 
> [% results = c.model('DB::Foo').search({ col => $value }) %]
> 
> This turns "results" into a list of records rather than an object I
> can call next(), first(), etc on.
> 
> I'll gladly RTFM if somebody can point me to the right FM.
> 
> Thanks.

My apologies. There IS code. I blame the long day and a trip the
Dr/Hospital.

Now that I see your code, I understand your problem. I too had the same
problem. I believe it has to do with the fact that the resultset
returned by DBIC is not really anything until it's used, and TT is
guessing wrong about how to use it.

Try adding this to your search:

   .search({ col => $value }, {cache => 1})

and see if that fixes it.

-=Chris

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060531/69fe72c7/attachment.pgp 


More information about the Catalyst mailing list