[Catalyst] Getting hashref instead of value

Robert Wohlfarth rbwohlfarth at gmail.com
Tue May 8 15:31:28 GMT 2012


On Tue, May 8, 2012 at 10:13 AM, Kenneth S Mclane <ksmclane at us.ibm.com>wrot=
e:

> I am having a problem with my code and I cannot figure out why it is doing
> what it is doing. I have this sub:
>
> sub list :Local {
>         my ($self, $c, $page) =3D @_;
>         $page =3D $c->req->param('page') || 1;
>         my $rs =3D $c->model('ORANGES::Account')->search({}, {
>                 join =3D> 'progress',
>                 '+select' =3D> ['progress.percent_complete'],
>                 '+as' =3D> ['progress.percent_complete'],
>                 join =3D> 'compliance',
>                 '+select' =3D> ['compliance.percent_compliant'],
>                 '+as' =3D> ['compliance.percent_compliant'],
>                 join =3D> 'department_id',
>                 '+select' =3D> ['department_id.department_id'],
>                 '+as' =3D> ['department_id.department_id'],
>                 join =3D> 'metrics',
>                 '+select' =3D>
> ['metrics.num_servers','metrics.num_subsystems'],
>                 '+as' =3D> ['metrics.num_servers','metrics.num_subsystems=
'],
>
>                 order_by =3D> 'account_code',
>                 rows =3D> 15,
>                 page =3D> $page,
>          });
>         $c->stash(accounts =3D> $rs);
>         $c->stash(pager =3D> $rs->pager());
>         $c->stash->{'template'}=3D>'accountview/list';
>
> }


I think this will solve the problem:
        my $rs =3D $c->model('ORANGES::Account')->search({}, {
                join =3D> 'progress',
                '+select' =3D> ['progress.percent_complete'],
                '+as' =3D> ['progress.percent_complete'],
                join =3D> 'compliance',
                '+select' =3D> ['compliance.percent_compliant'],
                '+as' =3D> ['compliance.percent_compliant'],
                join =3D> 'department_id',
                '+select' =3D> ['department_id.department_id'],
                '+as' =3D> ['department_id.department_id'],
                join =3D> 'metrics',
                '+select' =3D>
['metrics.num_servers','metrics.num_subsystems'],
                '+as' =3D> ['metrics.num_servers','metrics.num_subsystems'],

                order_by =3D> 'account_code',
                rows =3D> 15,
                page =3D> $page,
         })*->first*;

I added the "->first" to the end. A result is more like a query. "->first"
tells DBIx to execute the query and return a row object of the first one.

-- =

Robert Wohlfarth
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20120508/23b76=
28d/attachment.htm


More information about the Catalyst mailing list