Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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 }; };

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

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2021-10-25 17:08 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (89 votes). Check out past polls.