On 6/19/07, Matt S Trout <[EMAIL PROTECTED]> wrote:

On Tue, Jun 19, 2007 at 08:28:48PM +0100, Daniel Hulme wrote:
> On Tue, Jun 19, 2007 at 03:09:29PM -0400, John Goulah wrote:
> > 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 get both the iteratorish and the arrayish behaviour. If you
> call it in list context, you get a list, and you can iterate over it
> using FOREACH in your template and `for my $alumnus (@$alumni)` in your
> Perl code. If you call it in scalar context, you get an iterator, and
> you can iterate over it by calling $alumnus->next in your controller and
> alumnus.next in your template. If you really want it both ways, the
> obvious way is to call the thing twice, once in scalar context and once
> in list context, and only put one of them in the stash. Or you could
> call it in scalar context and when you iterate over the results in your
> controller add them to a list as well and put the arrayref in the stash.
> There may be a proper way to convert an iteratorish result into a list:
> I suspect the people on the DBIx::Class mailing list would know.

my @results = $rs->search(...);

is exactly equivalent to

my $result_rs = $rs->search(...);
my @results = $rs->all;

See


http://search.cpan.org/~mstrout/DBIx-Class-0.08001/lib/DBIx/Class/ResultSet.pm#search


http://search.cpan.org/~mstrout/DBIx-Class-0.08001/lib/DBIx/Class/ResultSet.pm#all

Amazing what you can learn if you actually read the documentation :)




Thanks guys that all helps a lot, I did read the docs but somehow missed
that (or perhaps I saw it but figured there was some way to get from scalar
to array or vice versa here)-
_______________________________________________
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/

Reply via email to