4

I use Catalyst and put a resultset into the stash for TT to access:

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

This class has a relationship with "tournament_participant" which I access from inside a TT page like this:

[% FOREACH participant IN tournament.tournament_participants -%]

problem is, I want to sort the result by a column like this:

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

but the above does not work (nothing is returned). Is this possible to do?

Gunnar
  • 351
  • 2
  • 9

1 Answers1

2

This should do the trick (assuming the relationship really is tournament_participants (which seems a little redundant and ungainly; tournament.participants feels more natural and is easy to change in the result class if desired)–

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

Doc: DBIx::Class::Relationship::Base.

Ashley
  • 4,307
  • 2
  • 19
  • 28
  • 1
    That was the right thing. Thanks! You are also right about naming and I do try to avoid redundancy, but there are several different participant types in this case, and I ilke to qualify them to avoid relying on context. It is a sacrifice for clarity. – Gunnar Mar 24 '11 at 11:41