Re: force resultset as array
Richard Thomas <[email protected]> Fri, 18 Oct 2013 22:22:18 +1100
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <[email protected]> |
> Problem is:
> when team has no accesses, variable team_accesses is empty string ('')
> when 1 access exists, variable contain hash which is result
> DBIx::TeamAccess.
> when exists more than 1 access, variable contains array of
> DBIx::TreamAccess.
> Is the way how to say TT, that result needs to be converted to array?
Checking for child zero is a good way to determine what to do with an indeterminate variable in this context.
[%- SET team_accesses = team.team_accesses.0 ? team.team_accesses : [ team.team_accesses ];
FOREACH access IN team_accesses;
....
END -%]
Hope that helps.
RET
Sent from my iPhone
> On 18 Oct 2013, at 10:03 pm, "Spevak, Martin" <[email protected]> wrote:
>
> Hello,
>
> I have small problem with TT while getting DBIx::ResultSet. For instance
> I have stash variable team which ich DBIx::Result (one entry). In DBIx
> exists relations team_accesses as has_many. So in TT I am using:
>
> team_accesses = team.team_accesses;
>
> Problem is:
> when team has no accesses, variable team_accesses is empty string ('')
> when 1 access exists, variable contain hash which is result
> DBIx::TeamAccess.
> when exists more than 1 access, variable contains array of
> DBIx::TreamAccess.
> Is the way how to say TT, that result needs to be converted to array?
>
> I tried: team_access = [ team.team_accesses ], but my results are,
> [ '' ], [DBIx::Result], [[DBIx::Result]]
>
> Thanks for help
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates