[Catalyst] iterating twice over the same resultset in the template?

Fernan Aguero fernan at iib.unsam.edu.ar
Wed Jan 3 19:43:44 GMT 2007


[ or perhaps 'is it possible to clone a resultset?' ]

Hi!

I'm building a form whose elements are items taken from the
db.  And I need these items to show up in different elements
(fieldsets) of the form. More or less something like this:

With items similar to:
 'checkbox' - Item 1
 'checkbox' - Item 2
 'checkbox' - Item 3

with parts that belong to:
 'checkbox' - Item 1
 'checkbox' - Item 2
 'checkbox' - Item 3


In my controller:
my $rs = $model->search( ... );
$c->stash->{items} = $rs;

In my template (TT):
<form ...>
<fieldset>
[% WHILE ( it = items.next() ) -%]
<input ... > [% it.name -%]
[% END -%]
</fieldset>

<fieldset>
[% WHILE ( it = items.next() ) -%]
<input ... > [% it.name -%]
[% END -%]
</fieldset>
</form>

The problem is that the resultset is empty when I try to
iterate over it the second time. 

So far the only way I've found to make this work is
to do N separate searches, fill N stash elements, et cetera 

$rs1 = $model->search( ... ); $c->stash->{rs1} = $rs1;
$rs2 = $model->search( ... ); $c->stash->{rs2} = $rs2;
...

[% WHILE ( it = rs1.next() ) -%] ...
[% WHILE ( it = rs2.next() ) -%] ...

Is there any other way to do this? Is it possible to clone a
resultset?

Thanks,

Fernan




More information about the Catalyst mailing list