[Dbix-class] How can I get default values for a new row

RAPPAZ Francois francois.rappaz at unifr.ch
Wed Apr 9 14:19:22 GMT 2014


I use the following to create a new row in my table:

(@{$self->{primary_keys}} is an array of the primary key's names for the table)

When a new_row button is pressed:

my %hash   = map { $_, undef } @{$self->{primary_keys}};
my $row = $rs->new_result(\%hash);
$self->{new_row} = $row;


And latter
$row->set_column($id, $value); # for those fields the user has a value to enter in

And then, when an Apply button is pressed

$row = $self->{new_row};
$result = $row->insert;

My problem is that I have a check box for example, that can't have a null value, its default value is 0 and it appears as uncheck on the GUI, however it is saved as undef and this generates an error. 

In the module for the table it is defined as  { data_type => "tinyint", default_value => 0, is_nullable => 0 },

The workaround is to check the box, save the row, and uncheck it before saying  $row->update
But I wonder if there is something more elegant...

Thanks

François 



More information about the DBIx-Class mailing list