[Catalyst] List/Scalar Context with TT + DBIC

Mark Blythe list at markblythe.com
Thu Jun 1 07:10:45 CEST 2006


Thanks for the suggestion, but unfortunately it didn't work.  The
behavior didn't change at all with the added "cache => 1" attribute.
Here's the simple test template:

[% SET results = c.model('DB::Foo').search({ col => $value }, { cache => 1 }) %]

[% results %]

This yields:

ARRAY(0x355f004)

Indeed, it's an array that I can then loop through and access the
rows.  I guess I'll have to write some non-template perl code
somewhere to solve this -- or wait for the search_rs method that
phaylon mentioned.

On 5/31/06, Christopher H. Laco <claco at chrislaco.com> wrote:
> 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.
>
>
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>
>
>
>



More information about the Catalyst mailing list