[Catalyst] RE: DBIC <-> JSON conversion for AJAX
Roland Philibert
rphilibert at aptina.com
Wed Sep 14 16:24:33 GMT 2011
Thanks for the tip Ronald, works like nicely.
Cheers,
Roland
From: Ronald J Kimball [mailto:rkimball at pangeamedia.com]
Sent: 14 September 2011 16:59
To: The elegant MVC web framework
Subject: Re: [Catalyst] RE: DBIC <-> JSON conversion for AJAX
On Wed, Sep 14, 2011 at 11:44 AM, Roland Philibert
<rphilibert at aptina.com> wrote:
I did try what you suggest as per:
sub thing_GET {
my ($self, $c) = @_;
$self->status_ok(
$c,
entity => $rs =
$c->model('DB::data)->search({},{result_class =>
'DBIx::Class::ResultClass::HashRefInflator',})->all
);
}
...but the json rest object was showing just the number of row retrieved
ie: {"rest":80}
That is not quite what Ian suggested. Scalar assignment (i.e. $rs =)
provides scalar context to the right-hand side, so you're calling all()
in scalar context, so you get the number of elements. Also, the
assignment to $rs is misleading, as you're not actually assigning a
ResultSet object to it, but rather the result of calling ->all() on a
ResultSet.
Try one of these approaches instead, which all do the same thing in
slightly different ways. Ian's original suggestion:
@arr = $c->model('DB::data)->search({},{result_class =>
'DBIx::Class::ResultClass::HashRefInflator',});
...
entity => \@arr
...
or, with an anonymous array instead of a temporary array variable:
...
entity => [$c->model('DB::data)->search({},{result_class =>
'DBIx::Class::ResultClass::HashRefInflator',})]
...
or, assigning the ResultSet to $rs first:
$rs = $c->model('DB::data)->search({},{result_class =>
'DBIx::Class::ResultClass::HashRefInflator',});
...
entity => [$rs->all],
...
Ronald
Aptina (UK) Limited, Century Court, Millennium Way, Bracknell, Berkshire, RG12 2XT. Registered in England No. 06570543.
This e-mail and any attachments contain confidential information and are solely for the review and use of the intended recipient. If you have received this e-mail in error, please notify the sender and destroy this e-mail and any copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110914/4e263a45/attachment.htm
More information about the Catalyst
mailing list