Re: force resultset as array
Dave Howorth <dhoworth-fDajt2Yx3S8pY9vWkoisglpr/1R2p/[email protected]> Fri, 18 Oct 2013 12:20:36 +0100
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Organization | MRC Laboratory for Molecular Biology |
| Message-ID | <[email protected]> |
Spevak, Martin wrote:
> Hello,
>
> I have small problem with TT while getting DBIx::ResultSet.
I suppose you are talking about DBIx::Class::ResultSet?
> 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]]
This is why the *_rs methods exist. So use team.team_accesses_rs and
step through the list with next instead of using an array. Or else
convert it to an arrayref in perl before passing it to TT.
HTH, Dave