HTML::FormHandler with DBIC update extra database column before update_model

80 Views Asked by At

I'm using HTML::FormHandler (with DBIC) and I want to update a field on my model that depends on another field submitted on the form. HTML::FormHandler has a section on handling extra database fields, and it says when a row is created to do this in before update_model:

before 'update_model' => sub {
   my $self = shift;

   $self->item->my_other_column( manipulate_value($self->field('my_field') );
};

This works when I add a new item, but not when I edit it. When I edit the item my_field is updated but my_other_column is not. Does anyone know how I can accomplish this?

1

There are 1 best solutions below

0
Chankey Pathak On

before 'update_model' works only when you add a new item.

From docs: If there is another database field that needs to be updated when a row is created, add an attribute to the form, and then process it with before 'update_model'.

Try around 'update_model'.