[Dbix-class] sub resultset in Template Toolkit presented as an array, not a resultset
tleffler at uw.edu
Wed Feb 4 18:29:34 GMT 2015
On 02/04/2015 09:23 AM, Peter Rabbitson wrote:
> On 02/04/2015 06:14 PM, Chris Welch wrote:
>> However, in my template (having stashed |$divisions|), I'm unable to
>> access the grid_positions_filled object because division.team_seaons
>> gives me an arrayref of team resultsets in that division:
>> # Loop through our divisions
>> FOREACH division IN divisions;
>> CALL c.log.debug(division.team_seasons); # The output of this is
>> something like: ARRAY(0x6f8318c)
> Any relationship accessor is also created with an <accessor_name>_rs
> variant, to work around *exactly* this (mis)feature of TT.
> What you want above is ...division.team_seasons_rs...
And to expound on *why* this is happening... TT works in list context by
default, so anything that can return a list of values will do so.
Meaning those resultset calls (which usually come down to search()'s)
return lists of rows versus another resultset object.
There are a couple of ways to tell TT to work in scalar context, one of
which Peter described above. Another is to use TT's Scalar plugin 
and do something like ...division.scalar.team_seasons...
I'd be interested in about hearing folks' experiences/pros/cons of using
_rs vs scalar vs ??? in TT.
More information about the DBIx-Class