[Dbix-class] sub resultset in Template Toolkit presented as an array, not a resultset

Chris Welch welch.chris at gmail.com
Wed Feb 4 17:14:58 GMT 2015


Hi folks

I'm relatively new to this, so sorry if this is a silly question - and
sorry if it goes to the wrong place (I'm still not sure it's not a Template
Toolkit issue):

I am developing a Catalyst application using DBIx::Class and Template
Toolkit; in the particular part I'm having issues with, I have a resultset
obtained using by calling the following function in my ResultSet schema:

    sub divisions_and_teams_in_season {
      my ( $self, $season, $grid ) = @_;

      return $self->search({
          "division_seasons.season"         => $season->id,
          "division_seasons.fixtures_grid"  => $grid->id,
        }, {
        prefetch  => [
          "division_seasons",
          {
            "team_seasons" => {
              "team" => [{
                  "club" => "venue"
                },
                "home_night"
              ]
            }
          }
        ],
        order_by  => {
          -asc => [ qw( division_seasons.rank team_seasons.grid_position
club.short_name team.name ) ]
        }
      });
    }


This returns the data as I would expect and I'm able to do the following in
my Controller code to get back my resultset and iterate through the
team_seasons:

    my $divisions = [
$c->model("DB::Division")->divisions_and_teams_in_season($current_season,
$c->stash->{grid}) ];

    foreach my $division ( @{ $divisions } ) {
      $c->log->debug( $division->team_seasons->grid_positions_filled ); #
This works I guess because $division->team_seasons is a resultset object
    }

However, in my template (having stashed $divisions), I'm unable to access
the grid_positions_filled object because division.team_seaons gives me an
arrayref of team resultsets in that division:

    [%
    # Loop through our divisions
    FOREACH division IN divisions;
      CALL c.log.debug(division.team_seasons); # The output of this is
something like: ARRAY(0x6f8318c)
    END;
    -%]

The output I get for the same debug log in my controller is more like a
list of resultset objects:


    TopTable::Model::DB::TeamSeason=HASH(0x6eea94c)
    TopTable::Model::DB::TeamSeason=HASH(0x6f01834)
    TopTable::Model::DB::TeamSeason=HASH(0x6ef5284)
    TopTable::Model::DB::TeamSeason=HASH(0x6efec9c)
    TopTable::Model::DB::TeamSeason=HASH(0x6ef4dc4)
    TopTable::Model::DB::TeamSeason=HASH(0x6faf0ac)
    TopTable::Model::DB::TeamSeason=HASH(0x6eefa04)

Hope all this makes sense! Does anyone know how I can get the behaviour
from the controller into the template so that I can access methods on the
team_season ResultSet?

Thank you very much in advance.


Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20150204/6a1d78a7/attachment.html>


More information about the DBIx-Class mailing list