从 Template Toolkit 内的结果集中访问额外选定的列

发布于 2024-10-10 01:16:09 字数 677 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

宫墨修音 2024-10-17 01:16:09

您需要同时使用 +as 选项和 +select,然后才能在模板中使用 result.get_column('column_name')。您还可以在结果类中定义一个访问器来为您进行 get_column 调用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文