Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing extra selected columns from a resultset inside 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 of 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 don't know how to access the extra selected items in resultset passed to the template.

like image 317
dj_goku Avatar asked Nov 27 '25 00:11

dj_goku


1 Answers

You need to make use of the +as option alongside +select then you can use result.get_column('column_name') in your template. You could also define an accessor in your result class to make the get_column call for you.

like image 152
Brian Phillips Avatar answered Nov 29 '25 17:11

Brian Phillips



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!