http://www.perlmonks.org?node_id=1223368

GertMT has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

While experimenting with Dancer2, DBIx::Class and HTML::FormFu I'm lost with some code that looks okay.. but doesn't work. Hopefully the limited set of lines is sufficient to give a hint about where I'm taking a wrong direction.

I've set up the database, schema. Everything seems to work. In the schema the 'Client' table belongs to 'Country' (a country can have multiple clients). With the following route set up in Dancer2 I get a list of clients.

# list clients get '/clients' => sub { my @clients_and_countries = resultset('Client')->search( {}, { join => ['country'], } ); template 'clients' => { clients => \@clients_and_countries }; };

The problem arises where I try to show a database record in a form so that I can make changes. Just the fields from a single table works but the field from the join doesn't show.

# change clients get '/client-bewerk/:id' => sub { my $id = route_parameters->get('id'); # no result my $client = resultset('Client') ->search( { 'client_id' => $id }, { join => ['country'], } ); # no result # my $client = resultset('Client')->search( { "client_id" => $id, +} ); # # This code works though... # my $client = resultset('Client')->find($id); # .... it doesn't show the Country # my $form = HTML::FormFu->new; $form->load_config_file("forms/addclient.yml"); $form->model('DBIC'); $form->stash( schema => $schema ); $form->model->default_values($client); template 'add-client', { myform => $form }; };

Replies are listed 'Best First'.
Re: Dancer2, DBIx::Class and HTML::FormFu: showing database record in html-form to edit
by 1nickt (Abbot) on Oct 02, 2018 at 00:11 UTC
      Thanks for the answer and the helpful reference to the specific chapters in the documents!