Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Dancer2, DBIx::Class and HTML::FormFu: showing database record in html-form to edit

by GertMT (Friar)
on Oct 01, 2018 at 20:48 UTC ( #1223368=perlquestion: print w/replies, xml ) Need Help??

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!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1223368]
Approved by marto
Front-paged by haukex
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (1)
As of 2021-09-16 18:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found