Dear All, I have been the following 2 methods in a Catalyst controller:
sub create :Chained('base') :PathPart('create') :FormConfig('author/edit.conf') { my ( $self, $c ) = @_; my $form = $c->stash->{form}; $form->stash( schema => $c->stash->{schema} ); if ( $form->submitted_and_valid ) { my $author = $form->stash->{schema}->resultset('Author')->new_result({}); $form->model->update($author); $c->response->redirect( $c->uri_for( $self->action_for('l +ist')) ); } $c->stash(template => 'author/formfu_create.tt2'); } sub edit :Chained('object') :PathPart('edit') :Args(0) :FormConfig('author/edit.conf') { my ( $self, $c, $id ) = @_; my $form = $c->stash->{form}; if ( $form->submitted_and_valid ) { $form->model->update($c->stash->{rs}); $c->response->redirect( $c->uri_for( $self->action_for +('list')) ); } else { $form->model->default_values($c->stash->{rs}); } $c->stash(template => 'author/formfu_create.tt2'); }
The methods give the following results:
Edit gives
SELECT me.id, me.name FROM author me WHERE ( me.id = ? ): '1'
UPDATE author SET name = ? WHERE ( id = ? ): 'scott', '1'
SELECT me.id, me.address, me.author_id FROM address me WHERE ( ( me.id = ? AND me.author_id = ? ) ): '1', '1'
UPDATE address SET address = ? WHERE ( id = ? ): '13 thriplee road', '1'

Create Gives
INSERT INTO author ( name) VALUES ( ? ): 'Marge'

...and finally the question. Why does the create method not do an insert into the address table and what do I have have to do to persuade the create method to do said insert?

In case it helps the object and based methods are:
sub base :Chained('/') :PathPart('author') :CaptureArgs(0) { my ($self, $c) = @_; my $someclass = $c->model('DB_APPLICATION'); my $schema = $someclass->connect( 'dbi:mysql:'.$c->session->{username}, $c->session->{username}, $c->session->{password}, { AutoCommit => 1 }, ); $c->stash(schema => $schema); } sub object :Chained('base') :PathPart('id') :CaptureArgs(1) { my ($self, $c, $id) = @_; # Find the period record and store it in the stash $c->stash(rs => $c->stash->{schema}->resultset('Author')->find($id +)); }
Thanks.

In reply to Catalyst FormFu Create Data in Related Table by simpzoid

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.