diff options
author | Dave Arter <davea@mysociety.org> | 2015-07-27 16:02:50 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2015-07-27 16:08:21 +0100 |
commit | 77a343a8d148abc4eb8922b645b25eefe0fae8c9 (patch) | |
tree | 30ff3dc84401cfc7cd3c98e41fc264e9861df9bd | |
parent | e30fda319976d871d3d28a0b749f2834b24ccde2 (diff) |
Use get_param_list instead of get_param for body areas
Because a body can cover more than one area, `area_ids` might contain
multiple values when updating or creating a body.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 76ee3447f..91d6be4fb 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -253,12 +253,9 @@ sub bodies : Path('bodies') : Args(0) { my $params = $c->forward('body_params'); my $body = $c->model('DB::Body')->create( $params ); - my $area_ids = $c->get_param('area_ids'); - if ($area_ids) { - $area_ids = [ $area_ids ] unless ref $area_ids; - foreach (@$area_ids) { - $c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } ); - } + my @area_ids = $c->get_param_list('area_ids'); + foreach (@area_ids) { + $c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } ); } $c->stash->{updated} = _('New body added'); @@ -413,13 +410,10 @@ sub update_contacts : Private { $c->stash->{body}->update( $params ); my @current = $c->stash->{body}->body_areas->all; my %current = map { $_->area_id => 1 } @current; - my $area_ids = $c->get_param('area_ids'); - if ($area_ids) { - $area_ids = [ $area_ids ] unless ref $area_ids; - foreach (@$area_ids) { - $c->model('DB::BodyArea')->find_or_create( { body => $c->stash->{body}, area_id => $_ } ); - delete $current{$_}; - } + my @area_ids = $c->get_param_list('area_ids'); + foreach (@area_ids) { + $c->model('DB::BodyArea')->find_or_create( { body => $c->stash->{body}, area_id => $_ } ); + delete $current{$_}; } # Remove any others $c->stash->{body}->body_areas->search( { area_id => [ keys %current ] } )->delete; |