Used it but at the same time, doing my $hashref = { $row->get_columns }
got me more or less the same effect for a lot less hassle :)
I actually do this for most my DB objects that get serialised to JSON,
quite simple case of $c->stash->{json} = [ map { $_->get_columns }
$rs->all ];
In a similar vein, I haven't yet really seen/heard any sort of "best
practices" when it comes to Catalyst and JSON, so maybe I'm going about
it all wrong but eh :)
Lee Aylward wrote:
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
--
Ben van Staveren
phone: +62 81 70777529
email: [email protected]
_______________________________________________
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/