[Catalyst] RE: DBIC <-> JSON conversion for AJAX
Ronald J Kimball
rkimball at pangeamedia.com
Wed Sep 14 15:59:25 GMT 2011
On Wed, Sep 14, 2011 at 11:44 AM, Roland Philibert <rphilibert at aptina.com>w=
rote:
> I did try what you suggest as per:
> sub thing_GET {
>
> my ($self, $c) =3D @_;
> $self->status_ok(
> $c,
> entity =3D> $rs =3D
> $c->model('DB::data)->search({},{result_class =3D>
> '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 =3D)
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 =3D $c->model('DB::data)->search({},{result_class
=3D> 'DBIx::Class::ResultClass::HashRefInflator',});
...
entity =3D> \@arr
...
or, with an anonymous array instead of a temporary array variable:
...
entity =3D> [$c->model('DB::data)->search({},{result_class
=3D> 'DBIx::Class::ResultClass::HashRefInflator',})]
...
or, assigning the ResultSet to $rs first:
$rs =3D $c->model('DB::data)->search({},{result_class
=3D> 'DBIx::Class::ResultClass::HashRefInflator',});
...
entity =3D> [$rs->all],
...
Ronald
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110914/58be5=
67c/attachment.htm
More information about the Catalyst
mailing list