[Dbix-class] Problem getting data from resultset
Kenneth S Mclane
ksmclane at us.ibm.com
Fri Jul 6 14:09:29 GMT 2012
> your code will only work for fields in the main table of your resultset,
> but will break for relations. for example,
> $data->department.department_code is not a valid accessor. you will have
> to parse your field definition and convert it into
> $data->department->department_code in order to retrieve the data.
>
> HTH
>
> patrick
>
> --
> Patrick Meidl ........................ patrick at pantheon.at
> Vienna, Austria ...................... http://gplus.to/pmeidl
Ok, I now have this code:
my @fields = qw/ department.department_code account_code account_name
account_policy compliance.percent_compliant metrics.num_servers
metrics.num_subsystems progress.percent_complete /;
foreach my $field (@fields) {
$ws->write($row, $col, $field);
$col++;
}
$col=0;
$row++;
while (my @data =$sr->next) {
foreach my $data (@data) {
foreach my $field (@fields) {
if ($field =~ /\./) {
$field = join( "->", split( /\./,
$field));
}
$ws->write($row, $col, $data->$field);
$col++;
}
$col=0;
}
$row++;
}
Which gives this error:
Caught exception in dbms::Controller::AccountView->list "Can't locate
object method "department->department_code" via package
"dbms::Model::ORANGES::Account" at
/opt/catalyst/dbms/script/../lib/dbms/Controller/AccountView.pm line 65."
The if replaces the "." with a "->" as you can see.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120706/ad09911d/attachment.htm
More information about the DBIx-Class
mailing list