+=head2 add_to_from_cgi
+
+$obj->add_to_from_cgi($r[, $opts]);
+
+Like add_to_* for has_many relationships but will add nay objects it can
+figure out from the data. It returns a list of objects it creates or nothing
+on error. Call cgi_update_errors with the calling object to get errors.
+Fatal errors are in the respective "FATAL" key.
+
+=cut
+
+sub add_to_from_cgi {
+ my ($self, $r, $opts) = @_;
+ $self->_croak( "add_to_from_cgi can only be called as an object method")
+ unless ref $self;
+ my ($errors, $validated, @created);
+
+
+ my $params = $opts->{params} || $r->params;
+ $opts->{params} = $self->classify_form_inputs($params);
+ ($validated, $errors) = $self->validate_all($r, $opts);
+
+
+ if (keys %$errors) {
+ $self->{_cgi_update_error} = $errors;
+ return;
+ }
+
+ # Insert all the data
+ foreach my $hm (keys %$validated) {
+ my ($obj, $errs) = $self->_create_related($hm, $validated->{$hm});
+ if (not $errs) {
+ push @created, $obj;
+ }else {
+ $errors->{$hm} = $errs;
+ }
+ }
+
+ if (keys %$errors) {
+ $self->{_cgi_update_error} = $errors;
+ return;
+ }
+
+ return @created;
+}
+
+
+
+