[Catalyst] List/Scalar Context with TT + DBIC

Christopher H. Laco claco at chrislaco.com
Wed May 31 22:54:41 CEST 2006

Christopher H. Laco wrote:
> 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.

When I had this problem, I could also mitigate it by calling
$result->count in the code, before returning the resultset. That's what
leads me to believe cache => 1 will probably fix it.

-------------- 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/30f897d0/attachment.pgp 

More information about the Catalyst mailing list