[% FOR resource = nation.resources %]
  • [% resource %]
  • [% END %] #### [% FOR resource = nation.resources %]
  • [% resource.resource %]
  • [% END %] ##
    ## sub view_nation : Regex('^nation/(\d+)$') { my ( $self, $c ) = @_; my $nid = $c->request->snippets->[0]; $c->stash->{nation} = $c->model('DB::Nation')->find({id => $nid}) || die "No such nation!"; $c->stash->{template} = 'nation/nation.tt2'; } #### package Game::Schema::Nation; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto Core/); __PACKAGE__->table('nation_info'); __PACKAGE__->add_columns(qw/id name owner/); __PACKAGE__->set_primary_key('id'); __PACKAGE__->belongs_to(user => 'Game::Schema::User', 'owner'); __PACKAGE__->has_many(map_nation_resource => 'Game::Schema::NationResource', 'nation_id'); __PACKAGE__->many_to_many(resources => 'map_nation_resource', 'resource'); =head1 NAME Game::Schema::Nation - A model object representing a nation. =cut 1; #### package Game::Schema::NationResource; use base qw/DBIx::Class/; # Load required DBIC stuff __PACKAGE__->load_components(qw/PK::Auto Core/); # Set the table name __PACKAGE__->table('nation_resources'); # Set columns in table __PACKAGE__->add_columns(qw/nation_id resource_id/); # Set the primary key for the table __PACKAGE__->set_primary_key(qw/nation_id resource_id/); __PACKAGE__->belongs_to(nation => 'Game::Schema::Nation', 'nation_id'); __PACKAGE__->belongs_to(resource => 'Game::Schema::Resource', 'resource_id'); =head1 NAME Game::Schema::NationResource - A model object representing the JOIN between Nations and Resources. =cut 1; #### package Game::Schema::Resource; use base qw/DBIx::Class/; # Load required DBIC stuff __PACKAGE__->load_components(qw/PK::Auto Core/); # Set the table name __PACKAGE__->table('resources'); # Set columns in table __PACKAGE__->add_columns(qw/id resource/); # Set the primary key for the table __PACKAGE__->set_primary_key('id'); __PACKAGE__->has_many(map_nation_resource => 'Game::Schema::NationResource', 'resource_id'); =head1 NAME Game::Schema::Resources - A model object representing a resource to a nation. =cut 1;