X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=blobdiff_plain;f=lib%2FCatalyst%2FController%2FDBIC%2FAPI.pm;h=a572fa8389c71d4c64f207e542786fc934efe62e;hp=837fbea0b9df34948e568b7de6ce5c39d87cc9d8;hb=8ee81496088e875e33f8b9cf289da3eb9940fa0e;hpb=39955b2a7f4bf1d69ba2159159ec40255e67a35c diff --git a/lib/Catalyst/Controller/DBIC/API.pm b/lib/Catalyst/Controller/DBIC/API.pm index 837fbea..a572fa8 100644 --- a/lib/Catalyst/Controller/DBIC/API.pm +++ b/lib/Catalyst/Controller/DBIC/API.pm @@ -374,6 +374,7 @@ sub list =method_protected list_munge_parameters list_munge_parameters is a noop by default. All arguments will be passed through without any manipulation. In order to successfully manipulate the parameters before the search is performed, simply access $c->req->search_parameters|search_attributes (ArrayRef and HashRef respectively), which correspond directly to ->search($parameters, $attributes). Parameter keys will be in already-aliased form. +To store the munged parameters call $c->req->_set_search_parameters($newparams) and $c->req->_set_search_attributes($newattrs). =cut @@ -748,7 +749,13 @@ sub update_object_relation { my ($self, $c, $object, $related_params, $relation) = @_; my $row = $object->find_related($relation, {} , {}); - $row->update($related_params); + + if ($row) { + $row->update($related_params); + } + else { + $object->create_related($relation, $related_params); + } } =method_protected insert_object_from_params @@ -760,8 +767,22 @@ insert_object_from_params sets the columns for the object, then calls ->insert sub insert_object_from_params { my ($self, $c, $object, $params) = @_; - $object->set_columns($params); + + my %rels; + while (my ($k, $v) = each %{ $params }) { + if (ref $v && !($v == JSON::Any::true || $v == JSON::Any::false)) { + $rels{$k} = $v; + } + else { + $object->set_column($k => $v); + } + } + $object->insert; + + while (my ($k, $v) = each %rels) { + $object->create_related($k, $v); + } } =method_protected delete_objects @@ -843,7 +864,7 @@ sub each_object_inflate { my ($self, $c, $object) = @_; - return { $object->get_inflated_columns }; + return { $object->get_columns }; } # from Catalyst::Action::Serialize