Skip to content

Commit

Permalink
Add subset conditions to item data on create or update (GH #57).
Browse files Browse the repository at this point in the history
We still need a similar change for related items.
  • Loading branch information
racke committed Feb 25, 2015
1 parent 3d4ab70 commit d48dc5c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/TableEdit/Routes/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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);
Expand Down

0 comments on commit d48dc5c

Please sign in to comment.