Access to additional selected columns from the result set inside the Template Toolkit

my $rs = schema->resultset('Table1')->search(
   undef,
   {
      join => 'relationship_table2',
      '+select' => ['relationship_table2.fk_id','relationship_table2.order],
      '+as'     => ['fk_id', 'order'],
   }
);

Inside the template (test.tt):

[% WHILE (result=rs.next) %]
table1.id    [% result.id   %] <!-- prints primary key for table1 -->
table1.name  [% result.name %] <!-- prints name of item for table1 -->
table2.order [% result.order %] <!-- doesn't work -->
table2.order [% result.relationship_table2.order %] <!-- doesn't work -->
[% END %]

I do not know how to access the additional selected elements in the result set passed to the template.

+3
source share
1 answer

You need to use the option +asnext to +select, then you can use result.get_column('column_name')in your template. You can also define an accessory in your results class to make get_column call for you.

+4
source

Source: https://habr.com/ru/post/1782417/


All Articles