From: Florian Ragwitz Date: Tue, 2 Mar 2010 04:30:53 +0000 (+0100) Subject: Create related rows on create. X-Git-Tag: 2.002001~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=commitdiff_plain;h=d8921389b13be6d1126ffa240b0a795541e30273 Create related rows on create. Kind of a lame hack because set_inflated_columns isn't quite working as i think it's supposed to. Giving control over creating the new, unstored, result from object_no_id to the creation thingy would probably fix this properly. --- diff --git a/lib/Catalyst/Controller/DBIC/API.pm b/lib/Catalyst/Controller/DBIC/API.pm index 0fe7635..66d775e 100644 --- a/lib/Catalyst/Controller/DBIC/API.pm +++ b/lib/Catalyst/Controller/DBIC/API.pm @@ -766,8 +766,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