2011-03-23 61 views
3

我使用的催化劑,把一個結果到藏匿於TT訪問:我可以從工具包模板文件中搜索結果集嗎?

$c->stash->{tournament} = $c->model('DB::Tournament')->find($id); 

這個類有「tournament_participant」這是我從一個TT頁面內訪問這樣的關係:

[% FOREACH participant IN tournament.tournament_participants -%] 

的問題是,我想通過這樣的列排序結果:

[% FOREACH participant IN tournament.tournament_participants.search({}, { sort_by => 'position' }) -%] 

但上述不起作用(什麼都不會返回)。這可能嗎?

回答

2

這應該做的伎倆(假設的關係真的是tournament_participants(這似乎有點多餘的,難看的; tournament.participants感覺更自然,易於如果需要在結果類改變)–

[% FOR participant IN tournament.search_related("tournament_participants", {}, { sort_by => 'position' }) -%] 

文件:DBIx::Class::Relationship::Base

+1

這是正確的。謝謝!你對命名也是對的,我儘量避免冗餘,但在這種情況下有幾種不同的參與者類型,我傾向於限定它們以避免依賴上下文這是爲了澄清而犧牲的。 – Gunnar 2011-03-24 11:41:01

相關問題