开发者

Accessing extra selected columns from a resultset inside Template Toolkit

my $rs = schema->resultset('Ta开发者_JS百科ble1')->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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜