从 Template Toolkit 内的结果集中访问额外选定的列
my $rs = schema->resultset('Table1')->search(
undef,
{
join => 'relationship_table2',
'+select' => ['relationship_table2.fk_id','relationship_table2.order],
'+as' => ['fk_id', 'order'],
}
);
模板内部(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 %]
我不知道如何访问传递给模板的结果集中的额外选定项目。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要同时使用
+as
选项和+select
,然后才能在模板中使用result.get_column('column_name')
。您还可以在结果类中定义一个访问器来为您进行 get_column 调用。You need to make use of the
+as
option alongside+select
then you can useresult.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.