开发者

Accessing extra selected columns from a resultset inside Template Toolkit

开发者 https://www.devze.com 2023-02-01 23:43 出处:网络
my $rs = schema->resultset(\'Ta开发者_JS百科ble1\')->search( undef, { join => \'relationship_table2\',
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

精彩评论

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