From d48dc5cd03c813e4cd227a69682c2cbe456a8676 Mon Sep 17 00:00:00 2001 From: "Stefan Hornburg (Racke)" Date: Wed, 25 Feb 2015 10:46:27 +0100 Subject: [PATCH] Add subset conditions to item data on create or update (GH #57). We still need a similar change for related items. --- lib/TableEdit/Routes/API.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/TableEdit/Routes/API.pm b/lib/TableEdit/Routes/API.pm index 41a110e..f0d7ad3 100644 --- a/lib/TableEdit/Routes/API.pm +++ b/lib/TableEdit/Routes/API.pm @@ -358,6 +358,7 @@ get '/:class' => require_login sub { return to_json($data, {allow_unknown => 1}); }; +# Updating item post '/:class' => require_login sub { my $class_info = schema_info->class(param('class')); @@ -366,7 +367,13 @@ post '/:class' => require_login sub { my $item = $body->{item}; return to_json {error => 'Please fill the form.'} unless $item->{values} and %{$item->{values}}; - debug "Updating item for ".$class_info->name.": ", $item; + # add subset conditions to item values + while (my ($col, $value) = each %{$class_info->subset_conditions}) { + next if ref($value); + $item->{values}->{$col} = $value; + } + debug "Updating item for ".$class_info->name.": ", $item; + my $object = $class_info->resultset->update_or_create( $item->{values} ); return to_json {error => 'Unable to save.'} unless $object; my $rowInfo = schema_info->row($object);