[Catalyst] iterating ResultSet in controller vs. template
Matt S Trout
dbix-class at trout.me.uk
Tue Jun 19 20:43:02 GMT 2007
On Tue, Jun 19, 2007 at 03:09:29PM -0400, John Goulah wrote:
> On 6/19/07, Michael Reece <mreece at vinq.com> wrote:
> >
> >i believe you are getting an array-ref because you are calling it in list
> >context via the [ ... ] here.
> >
> > my $myalums = [ $c->model('MyDB::Alumni')->search({}, { rows => 20 })
> >] ;
> >
> >
> >try:
> >
> > my $myalums_iter = $c->model('MyDB::Alumni')->search({}, { rows =>
> >20 });
> > while (my $alum = $myalums_iter->next) { ... }
> >
>
>
>
> You are correct (and I did explain that as well in my original post that was
> happening). So the question is , how can I make the same call and access
> the data in both places? It seems silly that I have to make the call
> without brackets to access in the controller, and with brackets to access in
> the template, so I assume I am accessing the object incorrectly in one place
> or the other, but I would like to be able to use ->next in the controller.
You don't have to, you're just abusing DBIx::Class :)
WHILE (alum = myalums.next);
in TT
-or-
FOREACH alum IN myalums.all;
will both work on resultset objects
Read the DBIx::Class::ResultSet docs for more details (and note ->reset which
you'll need if you want to iterate it twice)
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director Want a managed development or deployment platform?
Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/
More information about the Catalyst
mailing list