On Mon, 26 Apr 2010 16:33:31 +0700
Ben van Staveren <[email protected]> wrote:
> Probably not the most pretty one but:
>
> Given you have a resultset obtained with, say,
>
> my $result_set = $c->model('DB::Somedata')->search_rs({...}, {...});
>
> $c->stash->{json} = [
> map { id => $_->id, label => $_->name } ($result_set->all)
> ];
>
> Or a bit more verbose:
>
> foreach my $result ($result_set->all) {
> push(@{$c->stash->{json}}, { id => $result->id, label =>
> $result->name }); }
>
> `
>
I've also had good luck using DBIx::Class::RsultClass::HashRefInflator
in the past. It doesn't give you quite as much control, but it may be
enough for your needs.
http://search.cpan.org/~frew/DBIx-Class/lib/DBIx/Class/ResultClass/HashRefInflator.pm
--
Lee Aylward
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/