Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Getting hashref instead of value

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


ksmclane at us

May 8, 2012, 8:13 AM

Post #1 of 19 (857 views)
Permalink
Getting hashref instead of value

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) = @_;
$page = $c->req->param('page') || 1;
my $rs = $c->model('ORANGES::Account')->search({}, {
join => 'progress',
'+select' => ['progress.percent_complete'],
'+as' => ['progress.percent_complete'],
join => 'compliance',
'+select' => ['compliance.percent_compliant'],
'+as' => ['compliance.percent_compliant'],
join => 'department_id',
'+select' => ['department_id.department_id'],
'+as' => ['department_id.department_id'],
join => 'metrics',
'+select' =>
['metrics.num_servers','metrics.num_subsystems'],
'+as' => ['metrics.num_servers','metrics.num_subsystems'],

order_by => 'account_code',
rows => 15,
page => $page,
});
$c->stash(accounts => $rs);
$c->stash(pager => $rs->pager());
$c->stash->{'template'}=>'accountview/list';

}
Which I have tried in several different ways to fix this problem, but none
have worked so far. In my template file all my fields come up with the
valyes expected, except, I am trying to use the account_id field value as
part of a uri to take the user to a details page for the row. Where I am
expecting a uri such as 'http://127.0.0.1:3000/accountdetails/detail/170'
I instead get a uri like this:

http://127.0.0.1:3000/accountdetails/detail/dbms::Model::ORANGES::Account=HASH%280x5496460%29

This used to work when I was using a view as the basis for my list page.

When I run the page I can see in the sub-queries that it runs that it has
the "account_id" value as it uses it, but when I try to access it in my
template I get the hash ref. None of the other fields do this.

one of the sub queries using the account_id value:
SELECT me.account_id, me.account_code, me.percent_compliant FROM
HCDB_TEST.COMPLIANCE me WHERE ( me.account_id = ? ): '321'


My template that cretaes the uri:

<td><a href="[% c.uri_for('/accountdetails/detail/') %][%
account.account_id %]">[% account.account_code %]</a></td>

If someone could point me in the right direction, Ive been fighting this
for days.


billcrawford1970 at gmail

May 8, 2012, 8:24 AM

Post #2 of 19 (839 views)
Permalink
Re: Getting hashref instead of value [In reply to]

On 8 May 2012 16:13, Kenneth S Mclane <ksmclane [at] us> wrote:
> 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) = @_;
>         $page = $c->req->param('page') || 1;
>         my $rs = $c->model('ORANGES::Account')->search({}, {
...
> Where I am
> expecting a uri such as 'http://127.0.0.1:3000/accountdetails/detail/170'
> I instead get a uri like this:
> http://127.0.0.1:3000/accountdetails/detail/dbms::Model::ORANGES::Account=HASH%280x5496460%29
>
> This used to work when I was using a view as the basis for my list page.

When you changed this, how did you change the result class? This looks
suspiciously like "I regenerated the schema using an older version of
the schema loader" ..

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


ari.constancio at gmail

May 8, 2012, 8:25 AM

Post #3 of 19 (842 views)
Permalink
Re: Getting hashref instead of value [In reply to]

On Tue, May 8, 2012 at 4:13 PM, Kenneth S Mclane <ksmclane [at] us> wrote:
> My template that cretaes the uri:
>
> <td><a href="[% c.uri_for('/accountdetails/detail/') %][% account.account_id
> %]">[% account.account_code %]</a></td>
>
> If someone could point me in the right direction, Ive been fighting this for
> days.

Hi Kenneth,

I suppose you mean to use

[% c.uri_for('/accountdetails/detail/', account.account_id) %]

instead of

[% c.uri_for('/accountdetails/detail/') %][% account.account_id %]

Regards,
--
Ari Constncio
GPG Fingerprint: C7DA F3CC 0AC6 D8B8 AC91 1FE2 DDA7 EAF5 F61E F16C

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


steve at matsch

May 8, 2012, 8:25 AM

Post #4 of 19 (847 views)
Permalink
Re: Getting hashref instead of value [In reply to]

The 'account.account_id' referenced in your template I believe is being
interpreted as an object. Try 'account.account_id.id' instead. I am
presuming that your DBIC relationship is called 'account_id', and that
is what you are referencing currently in your template.

On 5/8/2012 11:13 AM, Kenneth S Mclane wrote:
> 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) = @_;
> $page = $c->req->param('page') || 1;
> my $rs = $c->model('ORANGES::Account')->search({}, {
> join => 'progress',
> '+select' => ['progress.percent_complete'],
> '+as' => ['progress.percent_complete'],
> join => 'compliance',
> '+select' => ['compliance.percent_compliant'],
> '+as' => ['compliance.percent_compliant'],
> join => 'department_id',
> '+select' => ['department_id.department_id'],
> '+as' => ['department_id.department_id'],
> join => 'metrics',
> '+select' =>
> ['metrics.num_servers','metrics.num_subsystems'],
> '+as' =>
> ['metrics.num_servers','metrics.num_subsystems'],
> order_by => 'account_code',
> rows => 15,
> page => $page,
> });
> $c->stash(accounts => $rs);
> $c->stash(pager => $rs->pager());
> $c->stash->{'template'}=>'accountview/list';
>
> }
> Which I have tried in several different ways to fix this problem, but
> none have worked so far. In my template file all my fields come up
> with the valyes expected, except, I am trying to use the account_id
> field value as part of a uri to take the user to a details page for
> the row. Where I am expecting a uri such as
> 'http://127.0.0.1:3000/accountdetails/detail/170'
> I instead get a uri like this:
>
> http://127.0.0.1:3000/accountdetails/detail/dbms::Model::ORANGES::Account=HASH%280x5496460%29
>
>
> This used to work when I was using a view as the basis for my list page.
>
> When I run the page I can see in the sub-queries that it runs that it
> has the "account_id" value as it uses it, but when I try to access it
> in my template I get the hash ref. None of the other fields do this.
>
> one of the sub queries using the account_id value:
> SELECT me.account_id, me.account_code, me.percent_compliant FROM
> HCDB_TEST.COMPLIANCE me WHERE ( me.account_id = ? ): '321'
>
>
> My template that cretaes the uri:
>
> <td><a href="[% c.uri_for('/accountdetails/detail/') %][%
> account.account_id %]">[% account.account_code %]</a></td>
>
> If someone could point me in the right direction, Ive been fighting
> this for days.
>
>
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


rbwohlfarth at gmail

May 8, 2012, 8:31 AM

Post #5 of 19 (841 views)
Permalink
Re: Getting hashref instead of value [In reply to]

On Tue, May 8, 2012 at 10:13 AM, Kenneth S Mclane <ksmclane [at] us>wrote:

> 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) = @_;
> $page = $c->req->param('page') || 1;
> my $rs = $c->model('ORANGES::Account')->search({}, {
> join => 'progress',
> '+select' => ['progress.percent_complete'],
> '+as' => ['progress.percent_complete'],
> join => 'compliance',
> '+select' => ['compliance.percent_compliant'],
> '+as' => ['compliance.percent_compliant'],
> join => 'department_id',
> '+select' => ['department_id.department_id'],
> '+as' => ['department_id.department_id'],
> join => 'metrics',
> '+select' =>
> ['metrics.num_servers','metrics.num_subsystems'],
> '+as' => ['metrics.num_servers','metrics.num_subsystems'],
>
> order_by => 'account_code',
> rows => 15,
> page => $page,
> });
> $c->stash(accounts => $rs);
> $c->stash(pager => $rs->pager());
> $c->stash->{'template'}=>'accountview/list';
>
> }


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

order_by => 'account_code',
rows => 15,
page => $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


fs5 at sanger

May 8, 2012, 8:31 AM

Post #6 of 19 (842 views)
Permalink
Re: Getting hashref instead of value [In reply to]

not sure if this is a problem but you should also collapse your joins,
selects and as' into ArrayRefs, as in
join => [ qw( progress compliance department_id ...)]

actually the last one looks suspicious. the relationships should be
called something like "departments", not department_ids. If you have the
same naming for accounts then an account_id is the name (presumably) of
a field in accounts and also a relationship
Frank


On 08/05/12 16:25, Steve wrote:
> The 'account.account_id' referenced in your template I believe is being
> interpreted as an object. Try 'account.account_id.id' instead. I am
> presuming that your DBIC relationship is called 'account_id', and that
> is what you are referencing currently in your template.
>
> On 5/8/2012 11:13 AM, Kenneth S Mclane wrote:
>> 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) = @_;
>> $page = $c->req->param('page') || 1;
>> my $rs = $c->model('ORANGES::Account')->search({}, {
>> join => 'progress',
>> '+select' => ['progress.percent_complete'],
>> '+as' => ['progress.percent_complete'],
>> join => 'compliance',
>> '+select' => ['compliance.percent_compliant'],
>> '+as' => ['compliance.percent_compliant'],
>> join => 'department_id',
>> '+select' => ['department_id.department_id'],
>> '+as' => ['department_id.department_id'],
>> join => 'metrics',
>> '+select' => ['metrics.num_servers','metrics.num_subsystems'],
>> '+as' => ['metrics.num_servers','metrics.num_subsystems'],
>> order_by => 'account_code',
>> rows => 15,
>> page => $page,
>> });
>> $c->stash(accounts => $rs);
>> $c->stash(pager => $rs->pager());
>> $c->stash->{'template'}=>'accountview/list';
>>
>> }
>> Which I have tried in several different ways to fix this problem, but
>> none have worked so far. In my template file all my fields come up
>> with the valyes expected, except, I am trying to use the account_id
>> field value as part of a uri to take the user to a details page for
>> the row. Where I am expecting a uri such as
>> 'http://127.0.0.1:3000/accountdetails/detail/170'
>> I instead get a uri like this:
>>
>> http://127.0.0.1:3000/accountdetails/detail/dbms::Model::ORANGES::Account=HASH%280x5496460%29
>>
>>
>> This used to work when I was using a view as the basis for my list page.
>>
>> When I run the page I can see in the sub-queries that it runs that it
>> has the "account_id" value as it uses it, but when I try to access it
>> in my template I get the hash ref. None of the other fields do this.
>>
>> one of the sub queries using the account_id value:
>> SELECT me.account_id, me.account_code, me.percent_compliant FROM
>> HCDB_TEST.COMPLIANCE me WHERE ( me.account_id = ? ): '321'
>>
>>
>> My template that cretaes the uri:
>>
>> <td><a href="[% c.uri_for('/accountdetails/detail/') %][%
>> account.account_id %]">[% account.account_code %]</a></td>
>>
>> If someone could point me in the right direction, Ive been fighting
>> this for days.
>>
>>
>>
>> _______________________________________________
>> List: Catalyst [at] lists
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive:
>> http://www.mail-archive.com/catalyst [at] lists/
>> Dev site: http://dev.catalyst.perl.org/
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/


--
The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


ksmclane at us

May 8, 2012, 8:33 AM

Post #7 of 19 (846 views)
Permalink
Re: Getting hashref instead of value [In reply to]

No, that just adds an extra"/" between the two parts of the uri.





From:
Ari Constancio <ari.constancio [at] gmail>
To:
The elegant MVC web framework <catalyst [at] lists>
Date:
05/08/2012 10:26 AM
Subject:
Re: [Catalyst] Getting hashref instead of value



On Tue, May 8, 2012 at 4:13 PM, Kenneth S Mclane <ksmclane [at] us>
wrote:
> My template that cretaes the uri:
>
> <td><a href="[% c.uri_for('/accountdetails/detail/') %][%
account.account_id
> %]">[% account.account_code %]</a></td>
>
> If someone could point me in the right direction, Ive been fighting this
for
> days.

Hi Kenneth,

I suppose you mean to use

[% c.uri_for('/accountdetails/detail/', account.account_id) %]

instead of

[% c.uri_for('/accountdetails/detail/') %][% account.account_id %]

Regards,
--
Ari Constncio
GPG Fingerprint: C7DA F3CC 0AC6 D8B8 AC91 1FE2 DDA7 EAF5 F61E F16C

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alexander.hartmaier at t-systems

May 8, 2012, 8:33 AM

Post #8 of 19 (844 views)
Permalink
Re: Getting hashref instead of value [In reply to]

Am 2012-05-08 17:25, schrieb Ari Constancio:
> On Tue, May 8, 2012 at 4:13 PM, Kenneth S Mclane <ksmclane [at] us> wrote:
>> My template that cretaes the uri:
>>
>> <td><a href="[% c.uri_for('/accountdetails/detail/') %][% account.account_id
>> %]">[% account.account_code %]</a></td>
>>
>> If someone could point me in the right direction, Ive been fighting this for
>> days.
> Hi Kenneth,
>
> I suppose you mean to use
>
> [% c.uri_for('/accountdetails/detail/', account.account_id) %]
>
> instead of
>
> [% c.uri_for('/accountdetails/detail/') %][% account.account_id %]
No he doesn't because he isn't using Chained but Local where the
dispatcher knows nothing about the number of args.

I assume that you have defined a relationship on the account_id column
without giving it a different name. This makes DBIx::Class inflate the
related row into an object.
Two solutions:
- use a different accessors for your relationships (that's what I'm doing)
- use acount.get_column('account_id') when you can to get the column
value instead of the related row

Also note that it's a common problem that Template Toolkit calls
everything in list context.
search_rs was added to DBIx::Class to make sure you always get a
resultset object and not a list of row objects.
>
> Regards,


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


ksmclane at us

May 8, 2012, 8:37 AM

Post #9 of 19 (840 views)
Permalink
Re: Getting hashref instead of value [In reply to]

I had previously created a view in the database itself. I realized this
isn't ideal for doing CRUD, so I instead started trying to "duplicate" the
view I had created "manually". The view was created with data from 4
tables that are the ones I am using here. Nothing was regenerated, I'm
just trying to do it a different way.

Regards



Kenneth McLane
700 Locust St

Systems Compliance Services
Dubuque, 52001-6838
I1OB
USA
GTS Services Delivery


Phone:
+1-563-845-4674


Tie-Line:
946-4674


Mobile:
+1-563-940-7147


e-mail:
ksmclane [at] us


"Ideas come from everything" -- Alfred Hitchcock






From:
Will Crawford <billcrawford1970 [at] gmail>
To:
The elegant MVC web framework <catalyst [at] lists>
Date:
05/08/2012 10:32 AM
Subject:
Re: [Catalyst] Getting hashref instead of value



On 8 May 2012 16:13, Kenneth S Mclane <ksmclane [at] us> wrote:
> 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) = @_;
> $page = $c->req->param('page') || 1;
> my $rs = $c->model('ORANGES::Account')->search({}, {
...
> Where I am
> expecting a uri such as
'http://127.0.0.1:3000/accountdetails/detail/170'
> I instead get a uri like this:
>
http://127.0.0.1:3000/accountdetails/detail/dbms::Model::ORANGES::Account=HASH%280x5496460%29

>
> This used to work when I was using a view as the basis for my list page.

When you changed this, how did you change the result class? This looks
suspiciously like "I regenerated the schema using an older version of
the schema loader" ..

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


ksmclane at us

May 8, 2012, 8:44 AM

Post #10 of 19 (848 views)
Permalink
Re: Getting hashref instead of value [In reply to]

The Catalyst helper script created most of the relationships. I added a
few at the bottom of the Account.pm file to since there are a bunch of
them based on "account_id", so I made them myself and gave them different
names. progress, metrics, compliance are ones I did. the one called
"department_id" was created by the helper and I didn"t want to chang it. I
guess I could redefine it below with a different name. Strangely, the
account table has a belongs to AND a has many to itself based on the
account_id field. I am actually looking to get a list nad that is what I
get except for the one field.



From:
Alexander Hartmaier <alexander.hartmaier [at] t-systems>
To:
<catalyst [at] lists>
Date:
05/08/2012 10:35 AM
Subject:
Re: [Catalyst] Getting hashref instead of value



Am 2012-05-08 17:25, schrieb Ari Constancio:
> On Tue, May 8, 2012 at 4:13 PM, Kenneth S Mclane <ksmclane [at] us>
wrote:
>> My template that cretaes the uri:
>>
>> <td><a href="[% c.uri_for('/accountdetails/detail/') %][%
account.account_id
>> %]">[% account.account_code %]</a></td>
>>
>> If someone could point me in the right direction, Ive been fighting
this for
>> days.
> Hi Kenneth,
>
> I suppose you mean to use
>
> [% c.uri_for('/accountdetails/detail/', account.account_id) %]
>
> instead of
>
> [% c.uri_for('/accountdetails/detail/') %][% account.account_id %]
No he doesn't because he isn't using Chained but Local where the
dispatcher knows nothing about the number of args.

I assume that you have defined a relationship on the account_id column
without giving it a different name. This makes DBIx::Class inflate the
related row into an object.
Two solutions:
- use a different accessors for your relationships (that's what I'm doing)
- use acount.get_column('account_id') when you can to get the column
value instead of the related row

Also note that it's a common problem that Template Toolkit calls
everything in list context.
search_rs was added to DBIx::Class to make sure you always get a
resultset object and not a list of row objects.
>
> Regards,


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


ksmclane at us

May 8, 2012, 8:46 AM

Post #11 of 19 (836 views)
Permalink
Re: Getting hashref instead of value [In reply to]

In checking through docs on line I find that prefetch is a better way to
go so I have changed ny sub thusly:

sub list :Local {
my ($self, $c, $page) = @_;
$page = $c->req->param('page') || 1;
my $rs = $c->model('ORANGES::Account')->search({}, {
prefetch => 'progress',
prefetch => 'compliance',
prefetch => 'department_id',
prefetch => 'metrics',
order_by => 'account_code',
rows => 15,
page => $page,
});
$c->stash(accounts => $rs);
$c->stash(pager => $rs->pager());
$c->stash->{'template'}=>'accountview/list';
}



From:
Frank Schwach <fs5 [at] sanger>
To:
catalyst [at] lists
Date:
05/08/2012 10:36 AM
Subject:
Re: [Catalyst] Getting hashref instead of value



not sure if this is a problem but you should also collapse your joins,
selects and as' into ArrayRefs, as in
join => [ qw( progress compliance department_id ...)]

actually the last one looks suspicious. the relationships should be
called something like "departments", not department_ids. If you have the
same naming for accounts then an account_id is the name (presumably) of
a field in accounts and also a relationship
Frank


On 08/05/12 16:25, Steve wrote:
> The 'account.account_id' referenced in your template I believe is being
> interpreted as an object. Try 'account.account_id.id' instead. I am
> presuming that your DBIC relationship is called 'account_id', and that
> is what you are referencing currently in your template.
>
> On 5/8/2012 11:13 AM, Kenneth S Mclane wrote:
>> 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) = @_;
>> $page = $c->req->param('page') || 1;
>> my $rs = $c->model('ORANGES::Account')->search({}, {
>> join => 'progress',
>> '+select' => ['progress.percent_complete'],
>> '+as' => ['progress.percent_complete'],
>> join => 'compliance',
>> '+select' => ['compliance.percent_compliant'],
>> '+as' => ['compliance.percent_compliant'],
>> join => 'department_id',
>> '+select' => ['department_id.department_id'],
>> '+as' => ['department_id.department_id'],
>> join => 'metrics',
>> '+select' => ['metrics.num_servers','metrics.num_subsystems'],
>> '+as' => ['metrics.num_servers','metrics.num_subsystems'],
>> order_by => 'account_code',
>> rows => 15,
>> page => $page,
>> });
>> $c->stash(accounts => $rs);
>> $c->stash(pager => $rs->pager());
>> $c->stash->{'template'}=>'accountview/list';
>>
>> }
>> Which I have tried in several different ways to fix this problem, but
>> none have worked so far. In my template file all my fields come up
>> with the valyes expected, except, I am trying to use the account_id
>> field value as part of a uri to take the user to a details page for
>> the row. Where I am expecting a uri such as
>> 'http://127.0.0.1:3000/accountdetails/detail/170'
>> I instead get a uri like this:
>>
>>
http://127.0.0.1:3000/accountdetails/detail/dbms::Model::ORANGES::Account=HASH%280x5496460%29

>>
>>
>> This used to work when I was using a view as the basis for my list
page.
>>
>> When I run the page I can see in the sub-queries that it runs that it
>> has the "account_id" value as it uses it, but when I try to access it
>> in my template I get the hash ref. None of the other fields do this.
>>
>> one of the sub queries using the account_id value:
>> SELECT me.account_id, me.account_code, me.percent_compliant FROM
>> HCDB_TEST.COMPLIANCE me WHERE ( me.account_id = ? ): '321'
>>
>>
>> My template that cretaes the uri:
>>
>> <td><a href="[% c.uri_for('/accountdetails/detail/') %][%
>> account.account_id %]">[% account.account_code %]</a></td>
>>
>> If someone could point me in the right direction, Ive been fighting
>> this for days.
>>
>>
>>
>> _______________________________________________
>> List: Catalyst [at] lists
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive:
>> http://www.mail-archive.com/catalyst [at] lists/
>> Dev site: http://dev.catalyst.perl.org/
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/


--
The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


billcrawford1970 at gmail

May 8, 2012, 8:48 AM

Post #12 of 19 (839 views)
Permalink
Re: Getting hashref instead of value [In reply to]

On 8 May 2012 16:44, Kenneth S Mclane <ksmclane [at] us> wrote:

> The Catalyst helper script created most of the relationships. I added a
> few at the bottom of the Account.pm file to since there are a bunch of them
> based on "account_id", so I made them myself and gave them different names.
> progress, metrics, compliance are ones I did. the one called
> "department_id" was created by the helper and I didn"t want to chang it. I
> guess I could redefine it below with a different name. Strangely, the
> account table has a belongs to AND a has many to itself based on the
> account_id field. I am actually looking to get a list nad that is what I
> get except for the one field.


Basically you just need to rename the relationship to call the accessor
"account" instead of "account_id", so that .account_id refers to the raw ID
column, not the object.


ksmclane at us

May 8, 2012, 8:54 AM

Post #13 of 19 (839 views)
Permalink
Re: Getting hashref instead of value [In reply to]

Here are the two relationships predefined in the account.pm file:

__PACKAGE__->belongs_to(
"account_id",
"dbms::Schema::Result::Account",
{ account_id => "account_id" },
);

=head2 accounts

Type: has_many

Related object: L<dbms::Schema::Result::Account>

=cut

__PACKAGE__->has_many(
"accounts",
"dbms::Schema::Result::Account",
{ "foreign.account_id" => "self.account_id" },
{},
);

So you're saying I should do this:

__PACKAGE__->belongs_to(
"account",
"dbms::Schema::Result::Account",
{ account_id => "account_id" },
);

?



From:
Will Crawford <billcrawford1970 [at] gmail>
To:
The elegant MVC web framework <catalyst [at] lists>
Date:
05/08/2012 10:49 AM
Subject:
Re: [Catalyst] Getting hashref instead of value





On 8 May 2012 16:44, Kenneth S Mclane <ksmclane [at] us> wrote:
The Catalyst helper script created most of the relationships. I added a
few at the bottom of the Account.pm file to since there are a bunch of
them based on "account_id", so I made them myself and gave them different
names. progress, metrics, compliance are ones I did. the one called
"department_id" was created by the helper and I didn"t want to chang it. I
guess I could redefine it below with a different name. Strangely, the
account table has a belongs to AND a has many to itself based on the
account_id field. I am actually looking to get a list nad that is what I
get except for the one field.

Basically you just need to rename the relationship to call the accessor
"account" instead of "account_id", so that .account_id refers to the raw
ID column, not the object._______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


billcrawford1970 at gmail

May 8, 2012, 8:59 AM

Post #14 of 19 (853 views)
Permalink
Re: Getting hashref instead of value [In reply to]

On 8 May 2012 16:54, Kenneth S Mclane <ksmclane [at] us> wrote:


> So you're saying I should do this:
>
> __PACKAGE__->belongs_to(
> "account",
> "dbms::Schema::Result::Account",
> { account_id => "account_id" },
> );
>
> ?


Looks right. We have quite a lot of *_id foreign key columns, and all the
accessors look like that.


fs5 at sanger

May 8, 2012, 9:03 AM

Post #15 of 19 (843 views)
Permalink
Re: Getting hashref instead of value [In reply to]

Yes, definitely change that relationship name, evne if it's just for
your sanity: saying that something belongs to an account_id makes no
sense and makes the code unintuitive.
To be honest, I'd ditch the Schema::Loader generated stuff at some
point. It's great to get started with the project but I just found that
it's much more trouble than it's worth in the long run to try and keep
the files in a state that can be auto-updated by the Schema::Loader,
especialyl once you are at a point where the schema becomes more stable
anyway.

Frank



On 08/05/12 16:54, Kenneth S Mclane wrote:
> Here are the two relationships predefined in the account.pm file:
>
> __PACKAGE__->belongs_to(
> "account_id",
> "dbms::Schema::Result::Account",
> { account_id => "account_id" },
> );
>
> =head2 accounts
>
> Type: has_many
>
> Related object: L<dbms::Schema::Result::Account>
>
> =cut
>
> __PACKAGE__->has_many(
> "accounts",
> "dbms::Schema::Result::Account",
> { "foreign.account_id" => "self.account_id" },
> {},
> );
>
> So you're saying I should do this:
>
> __PACKAGE__->belongs_to(
> "account",
> "dbms::Schema::Result::Account",
> { account_id => "account_id" },
> );
>
> ?
>
>
> From: Will Crawford <billcrawford1970 [at] gmail>
> To: The elegant MVC web framework <catalyst [at] lists>
> Date: 05/08/2012 10:49 AM
> Subject: Re: [Catalyst] Getting hashref instead of value
>
>
> ------------------------------------------------------------------------
>
>
>
>
>
> On 8 May 2012 16:44, Kenneth S Mclane <_ksmclane [at] us
> <mailto:ksmclane [at] us>> wrote:
> The Catalyst helper script created most of the relationships. I added a
> few at the bottom of the Account.pm file to since there are a bunch of
> them based on "account_id", so I made them myself and gave them
> different names. progress, metrics, compliance are ones I did. the one
> called "department_id" was created by the helper and I didn"t want to
> chang it. I guess I could redefine it below with a different name.
> Strangely, the account table has a belongs to AND a has many to itself
> based on the account_id field. I am actually looking to get a list nad
> that is what I get except for the one field.
>
> Basically you just need to rename the relationship to call the accessor
> "account" instead of "account_id", so that .account_id refers to the raw
> ID column, not the object._______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>
>
>
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/


--
The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alexander.hartmaier at t-systems

May 8, 2012, 9:05 AM

Post #16 of 19 (853 views)
Permalink
Re: Getting hashref instead of value [In reply to]

Am 2012-05-08 17:46, schrieb Kenneth S Mclane:
In checking through docs on line I find that prefetch is a better way to go so I have changed ny sub thusly:

sub list :Local {
my ($self, $c, $page) = @_;
$page = $c->req->param('page') || 1;
my $rs = $c->model('ORANGES::Account')->search({}, {
prefetch => 'progress',
prefetch => 'compliance',
prefetch => 'department_id',
prefetch => 'metrics',
order_by => 'account_code',
rows => 15,
page => $page,
});
$c->stash(accounts => $rs);
$c->stash(pager => $rs->pager());
$c->stash->{'template'}=>'accountview/list';
}
{} is a hashref in Perl. You're defining four values for the key 'prefetch', the last one overwrites the three previous ones.
As already noted you need to specify the prefetch value as arrayref in your case:
prefetch => [qw( progress compliance department_id metrics )],
FYI: qw() does nothing but saving you to quote every element of the list. It's equal to
prefetch => ['progress', 'compliance', 'department_id', 'metrics'],

Note that this is all basic Perl and nothing specific of Catalyst or DBIx::Class.


From: Frank Schwach <fs5 [at] sanger><mailto:fs5 [at] sanger>
To: catalyst [at] lists<mailto:catalyst [at] lists>
Date: 05/08/2012 10:36 AM
Subject: Re: [Catalyst] Getting hashref instead of value

________________________________



not sure if this is a problem but you should also collapse your joins,
selects and as' into ArrayRefs, as in
join => [ qw( progress compliance department_id ...)]

actually the last one looks suspicious. the relationships should be
called something like "departments", not department_ids. If you have the
same naming for accounts then an account_id is the name (presumably) of
a field in accounts and also a relationship
Frank


On 08/05/12 16:25, Steve wrote:
> The 'account.account_id' referenced in your template I believe is being
> interpreted as an object. Try 'account.account_id.id' instead. I am
> presuming that your DBIC relationship is called 'account_id', and that
> is what you are referencing currently in your template.
>
> On 5/8/2012 11:13 AM, Kenneth S Mclane wrote:
>> 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) = @_;
>> $page = $c->req->param('page') || 1;
>> my $rs = $c->model('ORANGES::Account')->search({}, {
>> join => 'progress',
>> '+select' => ['progress.percent_complete'],
>> '+as' => ['progress.percent_complete'],
>> join => 'compliance',
>> '+select' => ['compliance.percent_compliant'],
>> '+as' => ['compliance.percent_compliant'],
>> join => 'department_id',
>> '+select' => ['department_id.department_id'],
>> '+as' => ['department_id.department_id'],
>> join => 'metrics',
>> '+select' => ['metrics.num_servers','metrics.num_subsystems'],
>> '+as' => ['metrics.num_servers','metrics.num_subsystems'],
>> order_by => 'account_code',
>> rows => 15,
>> page => $page,
>> });
>> $c->stash(accounts => $rs);
>> $c->stash(pager => $rs->pager());
>> $c->stash->{'template'}=>'accountview/list';
>>
>> }
>> Which I have tried in several different ways to fix this problem, but
>> none have worked so far. In my template file all my fields come up
>> with the valyes expected, except, I am trying to use the account_id
>> field value as part of a uri to take the user to a details page for
>> the row. Where I am expecting a uri such as
>> 'http://127.0.0.1:3000/accountdetails/detail/170'
>> I instead get a uri like this:
>>
>> http://127.0.0.1:3000/accountdetails/detail/dbms::Model::ORANGES::Account=HASH%280x5496460%29
>>
>>
>> This used to work when I was using a view as the basis for my list page.
>>
>> When I run the page I can see in the sub-queries that it runs that it
>> has the "account_id" value as it uses it, but when I try to access it
>> in my template I get the hash ref. None of the other fields do this.
>>
>> one of the sub queries using the account_id value:
>> SELECT me.account_id, me.account_code, me.percent_compliant FROM
>> HCDB_TEST.COMPLIANCE me WHERE ( me.account_id = ? ): '321'
>>
>>
>> My template that cretaes the uri:
>>
>> <td><a href="[% c.uri_for('/accountdetails/detail/') %][%
>> account.account_id %]">[% account.account_code %]</a></td>
>>
>> If someone could point me in the right direction, Ive been fighting
>> this for days.
>>
>>
>>
>> _______________________________________________
>> List: Catalyst [at] lists<mailto:Catalyst [at] lists>
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive:
>> http://www.mail-archive.com/catalyst [at] lists/
>> Dev site: http://dev.catalyst.perl.org/
>
> _______________________________________________
> List: Catalyst [at] lists<mailto:Catalyst [at] lists>
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/


--
The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.

_______________________________________________
List: Catalyst [at] lists<mailto:Catalyst [at] lists>
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/






_______________________________________________
List: Catalyst [at] lists<mailto:Catalyst [at] lists>
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/



*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*


ksmclane at us

May 8, 2012, 9:15 AM

Post #17 of 19 (842 views)
Permalink
Re: Getting hashref instead of value [In reply to]

Yes, in changing things back and forth I forgot about that. I got that
fixed and changed the relationship names. I have tried with "search" and
"search_rs" and still have the same result of getting the object instead
of the value. Can I use "get_column" in TT?



From:
Alexander Hartmaier <alexander.hartmaier [at] t-systems>
To:
<catalyst [at] lists>
Date:
05/08/2012 11:07 AM
Subject:
Re: [Catalyst] Getting hashref instead of value



Am 2012-05-08 17:46, schrieb Kenneth S Mclane:
In checking through docs on line I find that prefetch is a better way to
go so I have changed ny sub thusly:

sub list :Local {
my ($self, $c, $page) = @_;
$page = $c->req->param('page') || 1;
my $rs = $c->model('ORANGES::Account')->search({}, {
prefetch => 'progress',
prefetch => 'compliance',
prefetch => 'department_id',
prefetch => 'metrics',
order_by => 'account_code',
rows => 15,
page => $page,
});
$c->stash(accounts => $rs);
$c->stash(pager => $rs->pager());
$c->stash->{'template'}=>'accountview/list';
}
{} is a hashref in Perl. You're defining four values for the key
'prefetch', the last one overwrites the three previous ones.
As already noted you need to specify the prefetch value as arrayref in
your case:
prefetch => [qw( progress compliance department_id metrics )],
FYI: qw() does nothing but saving you to quote every element of the list.
It's equal to
prefetch => ['progress', 'compliance', 'department_id', 'metrics'],

Note that this is all basic Perl and nothing specific of Catalyst or
DBIx::Class.


From:
Frank Schwach <fs5 [at] sanger>
To:
catalyst [at] lists
Date:
05/08/2012 10:36 AM
Subject:
Re: [Catalyst] Getting hashref instead of value




not sure if this is a problem but you should also collapse your joins,
selects and as' into ArrayRefs, as in
join => [ qw( progress compliance department_id ...)]

actually the last one looks suspicious. the relationships should be
called something like "departments", not department_ids. If you have the
same naming for accounts then an account_id is the name (presumably) of
a field in accounts and also a relationship
Frank


On 08/05/12 16:25, Steve wrote:
> The 'account.account_id' referenced in your template I believe is being
> interpreted as an object. Try 'account.account_id.id' instead. I am
> presuming that your DBIC relationship is called 'account_id', and that
> is what you are referencing currently in your template.
>
> On 5/8/2012 11:13 AM, Kenneth S Mclane wrote:
>> 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) = @_;
>> $page = $c->req->param('page') || 1;
>> my $rs = $c->model('ORANGES::Account')->search({}, {
>> join => 'progress',
>> '+select' => ['progress.percent_complete'],
>> '+as' => ['progress.percent_complete'],
>> join => 'compliance',
>> '+select' => ['compliance.percent_compliant'],
>> '+as' => ['compliance.percent_compliant'],
>> join => 'department_id',
>> '+select' => ['department_id.department_id'],
>> '+as' => ['department_id.department_id'],
>> join => 'metrics',
>> '+select' => ['metrics.num_servers','metrics.num_subsystems'],
>> '+as' => ['metrics.num_servers','metrics.num_subsystems'],
>> order_by => 'account_code',
>> rows => 15,
>> page => $page,
>> });
>> $c->stash(accounts => $rs);
>> $c->stash(pager => $rs->pager());
>> $c->stash->{'template'}=>'accountview/list';
>>
>> }
>> Which I have tried in several different ways to fix this problem, but
>> none have worked so far. In my template file all my fields come up
>> with the valyes expected, except, I am trying to use the account_id
>> field value as part of a uri to take the user to a details page for
>> the row. Where I am expecting a uri such as
>> 'http://127.0.0.1:3000/accountdetails/detail/170'
>> I instead get a uri like this:
>>
>>
http://127.0.0.1:3000/accountdetails/detail/dbms::Model::ORANGES::Account=HASH%280x5496460%29

>>
>>
>> This used to work when I was using a view as the basis for my list
page.
>>
>> When I run the page I can see in the sub-queries that it runs that it
>> has the "account_id" value as it uses it, but when I try to access it
>> in my template I get the hash ref. None of the other fields do this.
>>
>> one of the sub queries using the account_id value:
>> SELECT me.account_id, me.account_code, me.percent_compliant FROM
>> HCDB_TEST.COMPLIANCE me WHERE ( me.account_id = ? ): '321'
>>
>>
>> My template that cretaes the uri:
>>
>> <td><a href="[% c.uri_for('/accountdetails/detail/') %][%
>> account.account_id %]">[% account.account_code %]</a></td>
>>
>> If someone could point me in the right direction, Ive been fighting
>> this for days.
>>
>>
>>
>> _______________________________________________
>> List: Catalyst [at] lists
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive:
>> http://www.mail-archive.com/catalyst [at] lists/
>> Dev site: http://dev.catalyst.perl.org/
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/


--
The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/





_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/



*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alexander.hartmaier at t-systems

May 8, 2012, 9:23 AM

Post #18 of 19 (844 views)
Permalink
Re: Getting hashref instead of value [In reply to]

Am 2012-05-08 18:15, schrieb Kenneth S Mclane:
> Yes, in changing things back and forth I forgot about that. I got that
> fixed and changed the relationship names. I have tried with "search"
> and "search_rs" and still have the same result of getting the object
> instead of the value. Can I use "get_column" in TT?
Yes, you only have to use . instead of -> for method calls.
>
>
> From: Alexander Hartmaier <alexander.hartmaier [at] t-systems>
> To: <catalyst [at] lists>
> Date: 05/08/2012 11:07 AM
> Subject: Re: [Catalyst] Getting hashref instead of value
>
>
> ------------------------------------------------------------------------
>
>
>
> Am 2012-05-08 17:46, schrieb Kenneth S Mclane:
> In checking through docs on line I find that prefetch is a better way
> to go so I have changed ny sub thusly:
>
> sub list :Local {
> my ($self, $c, $page) = @_;
> $page = $c->req->param('page') || 1;
> my $rs = $c->model('ORANGES::Account')->search({}, {
> prefetch => 'progress',
> prefetch => 'compliance',
> prefetch => 'department_id',
> prefetch => 'metrics',
> order_by => 'account_code',
> rows => 15,
> page => $page,
> });
> $c->stash(accounts => $rs);
> $c->stash(pager => $rs->pager());
> $c->stash->{'template'}=>'accountview/list';
> }
> {} is a hashref in Perl. You're defining four values for the key
> 'prefetch', the last one overwrites the three previous ones.
> As already noted you need to specify the prefetch value as arrayref in
> your case:
> prefetch => [qw( progress compliance department_id metrics )],
> FYI: qw() does nothing but saving you to quote every element of the
> list. It's equal to
> prefetch => ['progress', 'compliance', 'department_id', 'metrics'],
>
> Note that this is all basic Perl and nothing specific of Catalyst or
> DBIx::Class.
>
> From: Frank Schwach _<fs5 [at] sanger>_ <mailto:fs5 [at] sanger>
> To: _catalyst [at] lists <mailto:catalyst [at] lists>
> Date: 05/08/2012 10:36 AM
> Subject: Re: [Catalyst] Getting hashref instead of value
>
>
>
> ------------------------------------------------------------------------
>
>
>
> not sure if this is a problem but you should also collapse your joins,
> selects and as' into ArrayRefs, as in
> join => [ qw( progress compliance department_id ...)]
>
> actually the last one looks suspicious. the relationships should be
> called something like "departments", not department_ids. If you have the
> same naming for accounts then an account_id is the name (presumably) of
> a field in accounts and also a relationship
> Frank
>
>
> On 08/05/12 16:25, Steve wrote:
> > The 'account.account_id' referenced in your template I believe is being
> > interpreted as an object. Try 'account.account_id.id' instead. I am
> > presuming that your DBIC relationship is called 'account_id', and that
> > is what you are referencing currently in your template.
> >
> > On 5/8/2012 11:13 AM, Kenneth S Mclane wrote:
> >> 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) = @_;
> >> $page = $c->req->param('page') || 1;
> >> my $rs = $c->model('ORANGES::Account')->search({}, {
> >> join => 'progress',
> >> '+select' => ['progress.percent_complete'],
> >> '+as' => ['progress.percent_complete'],
> >> join => 'compliance',
> >> '+select' => ['compliance.percent_compliant'],
> >> '+as' => ['compliance.percent_compliant'],
> >> join => 'department_id',
> >> '+select' => ['department_id.department_id'],
> >> '+as' => ['department_id.department_id'],
> >> join => 'metrics',
> >> '+select' => ['metrics.num_servers','metrics.num_subsystems'],
> >> '+as' => ['metrics.num_servers','metrics.num_subsystems'],
> >> order_by => 'account_code',
> >> rows => 15,
> >> page => $page,
> >> });
> >> $c->stash(accounts => $rs);
> >> $c->stash(pager => $rs->pager());
> >> $c->stash->{'template'}=>'accountview/list';
> >>
> >> }
> >> Which I have tried in several different ways to fix this problem, but
> >> none have worked so far. In my template file all my fields come up
> >> with the valyes expected, except, I am trying to use the account_id
> >> field value as part of a uri to take the user to a details page for
> >> the row. Where I am expecting a uri such as
> >> '_http://127.0.0.1:3000/accountdetails/detail/170_'
> >> I instead get a uri like this:
> >>
> >>
> _http://127.0.0.1:3000/accountdetails/detail/dbms::Model::ORANGES::Account=HASH%280x5496460%29_
> >>
> >>
> >> This used to work when I was using a view as the basis for my list
> page.
> >>
> >> When I run the page I can see in the sub-queries that it runs that it
> >> has the "account_id" value as it uses it, but when I try to access it
> >> in my template I get the hash ref. None of the other fields do this.
> >>
> >> one of the sub queries using the account_id value:
> >> SELECT me.account_id, me.account_code, me.percent_compliant FROM
> >> HCDB_TEST.COMPLIANCE me WHERE ( me.account_id = ? ): '321'
> >>
> >>
> >> My template that cretaes the uri:
> >>
> >> <td><a href="[% c.uri_for('/accountdetails/detail/') %][%
> >> account.account_id %]">[% account.account_code %]</a></td>
> >>
> >> If someone could point me in the right direction, Ive been fighting
> >> this for days.
> >>
> >>
> >>
> >> _______________________________________________
> >> List: _Catalyst [at] lists <mailto:Catalyst [at] lists>
> >> Listinfo: _http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst_
> >> Searchable archive:
> >> _http://www.mail-archive.com/catalyst [at] lists/_
> >> Dev site: _http://dev.catalyst.perl.org/_
> >
> > _______________________________________________
> > List: _Catalyst [at] lists <mailto:Catalyst [at] lists>
> > Listinfo: _http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst_
> > Searchable archive:
> _http://www.mail-archive.com/catalyst [at] lists/_
> > Dev site: _http://dev.catalyst.perl.org/_
>
>
> --
> The Wellcome Trust Sanger Institute is operated by Genome Research
> Limited, a charity registered in England with number 1021457 and a
> company registered in England with number 2742969, whose registered
> office is 215 Euston Road, London, NW1 2BE.
>
> _______________________________________________
> List: _Catalyst [at] lists <mailto:Catalyst [at] lists>
> Listinfo: _http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst_
> Searchable archive:
> _http://www.mail-archive.com/catalyst [at] lists/_
> Dev site: _http://dev.catalyst.perl.org/_
>
>
>
>
>
> _______________________________________________
> List: _Catalyst [at] lists <mailto:Catalyst [at] lists>
> Listinfo: _http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst_
> Searchable archive:
> _http://www.mail-archive.com/catalyst [at] lists/_
> Dev site: _http://dev.catalyst.perl.org/_
>
>
>
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
> Handelsgericht Wien, FN 79340b
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> Notice: This e-mail contains information that is confidential and may
> be privileged.
> If you are not the intended recipient, please notify the sender and then
> delete this e-mail immediately.
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*_______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>
>
>
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/


ksmclane at us

May 8, 2012, 9:25 AM

Post #19 of 19 (839 views)
Permalink
Re: Getting hashref instead of value [In reply to]

To answer my own question, yes I can use "get_column" in a TT file. Thanks
for all the help. Not only is it working but fixing the prefetch cut my
processing time in half serving the page.



From:
Alexander Hartmaier <alexander.hartmaier [at] t-systems>
To:
<catalyst [at] lists>
Date:
05/08/2012 11:07 AM
Subject:
Re: [Catalyst] Getting hashref instead of value



Am 2012-05-08 17:46, schrieb Kenneth S Mclane:
In checking through docs on line I find that prefetch is a better way to
go so I have changed ny sub thusly:

sub list :Local {
my ($self, $c, $page) = @_;
$page = $c->req->param('page') || 1;
my $rs = $c->model('ORANGES::Account')->search({}, {
prefetch => 'progress',
prefetch => 'compliance',
prefetch => 'department_id',
prefetch => 'metrics',
order_by => 'account_code',
rows => 15,
page => $page,
});
$c->stash(accounts => $rs);
$c->stash(pager => $rs->pager());
$c->stash->{'template'}=>'accountview/list';
}
{} is a hashref in Perl. You're defining four values for the key
'prefetch', the last one overwrites the three previous ones.
As already noted you need to specify the prefetch value as arrayref in
your case:
prefetch => [qw( progress compliance department_id metrics )],
FYI: qw() does nothing but saving you to quote every element of the list.
It's equal to
prefetch => ['progress', 'compliance', 'department_id', 'metrics'],

Note that this is all basic Perl and nothing specific of Catalyst or
DBIx::Class.


From:
Frank Schwach <fs5 [at] sanger>
To:
catalyst [at] lists
Date:
05/08/2012 10:36 AM
Subject:
Re: [Catalyst] Getting hashref instead of value




not sure if this is a problem but you should also collapse your joins,
selects and as' into ArrayRefs, as in
join => [ qw( progress compliance department_id ...)]

actually the last one looks suspicious. the relationships should be
called something like "departments", not department_ids. If you have the
same naming for accounts then an account_id is the name (presumably) of
a field in accounts and also a relationship
Frank


On 08/05/12 16:25, Steve wrote:
> The 'account.account_id' referenced in your template I believe is being
> interpreted as an object. Try 'account.account_id.id' instead. I am
> presuming that your DBIC relationship is called 'account_id', and that
> is what you are referencing currently in your template.
>
> On 5/8/2012 11:13 AM, Kenneth S Mclane wrote:
>> 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) = @_;
>> $page = $c->req->param('page') || 1;
>> my $rs = $c->model('ORANGES::Account')->search({}, {
>> join => 'progress',
>> '+select' => ['progress.percent_complete'],
>> '+as' => ['progress.percent_complete'],
>> join => 'compliance',
>> '+select' => ['compliance.percent_compliant'],
>> '+as' => ['compliance.percent_compliant'],
>> join => 'department_id',
>> '+select' => ['department_id.department_id'],
>> '+as' => ['department_id.department_id'],
>> join => 'metrics',
>> '+select' => ['metrics.num_servers','metrics.num_subsystems'],
>> '+as' => ['metrics.num_servers','metrics.num_subsystems'],
>> order_by => 'account_code',
>> rows => 15,
>> page => $page,
>> });
>> $c->stash(accounts => $rs);
>> $c->stash(pager => $rs->pager());
>> $c->stash->{'template'}=>'accountview/list';
>>
>> }
>> Which I have tried in several different ways to fix this problem, but
>> none have worked so far. In my template file all my fields come up
>> with the valyes expected, except, I am trying to use the account_id
>> field value as part of a uri to take the user to a details page for
>> the row. Where I am expecting a uri such as
>> 'http://127.0.0.1:3000/accountdetails/detail/170'
>> I instead get a uri like this:
>>
>>
http://127.0.0.1:3000/accountdetails/detail/dbms::Model::ORANGES::Account=HASH%280x5496460%29

>>
>>
>> This used to work when I was using a view as the basis for my list
page.
>>
>> When I run the page I can see in the sub-queries that it runs that it
>> has the "account_id" value as it uses it, but when I try to access it
>> in my template I get the hash ref. None of the other fields do this.
>>
>> one of the sub queries using the account_id value:
>> SELECT me.account_id, me.account_code, me.percent_compliant FROM
>> HCDB_TEST.COMPLIANCE me WHERE ( me.account_id = ? ): '321'
>>
>>
>> My template that cretaes the uri:
>>
>> <td><a href="[% c.uri_for('/accountdetails/detail/') %][%
>> account.account_id %]">[% account.account_code %]</a></td>
>>
>> If someone could point me in the right direction, Ive been fighting
>> this for days.
>>
>>
>>
>> _______________________________________________
>> List: Catalyst [at] lists
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive:
>> http://www.mail-archive.com/catalyst [at] lists/
>> Dev site: http://dev.catalyst.perl.org/
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/


--
The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/





_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/



*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.