Re: force resultset as array
Simon Amor <[email protected]> Fri, 18 Oct 2013 12:15:41 +0100
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <[email protected]> |
On 18 Oct 2013, at 12:03, "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]] It sounds similar to what I had problems with. DB::Result::Account contains __PACKAGE__->has_many(characters => 'DB::Result::Character', 'account_id' ); The solution I ended up with was as follows. SET character_rs = account.characters_rs; SET characters = character_rs.all; "There are " _ character_rs.count _ " characters.\n"; FOREACH character IN characters; character.name _ "\n"; END; Perhaps something like that (_rs.all) would work? Regards, Simon -- Simon Amor [email protected]