[Dancer-users] Plugin::SimpleCRUD: primary key missing from edit form

David Precious davidp at preshweb.co.uk
Thu Oct 20 17:42:44 CEST 2011


On Thursday 20 October 2011 14:49:19 WK wrote:
> 2011/10/20 WK <wanradt at gmail.com>:
> > It should begin:
> >        if (exists params->{id}) {
> 
> I changed it to:
> Line 462:
>        if (exists params->{id}) {
> 
>            # We're editing an existing record
>            $success = database->quick_update($table_name,
>                { $key_column => params->{id} }, \%params);
>            $verb = 'update';
>        } else {
> 
> Works for me. Sorry for messing here solo!

That looks to be a sensible and sane fix - thanks for catching, reporting and 
fixing this issue!

I'll get a new version out soon with that change.

I'll also see if I can handle Issue 11 at the same time:
https://github.com/bigpresh/Dancer-Plugin-SimpleCRUD/issues/11

To support multiple keys, I think I might need to add an "editing" flag rather 
than just test for the presence of the 'id' field; then, I can add each of the 
key columns to the URL (or perhaps as hidden form fields), use them all in the 
WHERE clause of the update - for e.g., if simple_crud() was called with 
key_column => [qw/key_1 key_2 key_3/], then that section of editing code would 
become something like:

if (params->{simplecrud_mode} eq 'editing') {
    my %where;
    my @key_cols = ref $key_column ? @$key_column : ($key_column);
    for my $key_col (@key_cols) {
        $where{$key_col} = params->{$key_col};
    }

    $success = database->quick_update($table_name, \%where, \%params);
    $verb = 'update';
}


At a quick glance, a change similar to above should take care of both the 
problem you were seeing, and saberworks' need for composite keys.



-- 
David Precious <davidp at preshweb.co.uk> (bigpresh)
http://www.preshweb.co.uk/

  "Programming is like sex. One mistake and you have to support 
  it for the rest of your life". (Michael Sinz)


More information about the Dancer-users mailing list