Create related rows on create.
Florian Ragwitz [Tue, 2 Mar 2010 04:30:53 +0000 (05:30 +0100)]
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.

lib/Catalyst/Controller/DBIC/API.pm

index 0fe7635..66d775e 100644 (file)
@@ -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