Index: t/update/belongs_to_create.t =================================================================== --- t/update/belongs_to_create.t (revision 0) +++ t/update/belongs_to_create.t (revision 0) @@ -0,0 +1,41 @@ +use strict; +use warnings; +use Test::More; + +use HTML::FormFu; +use lib 't/lib'; +use DBICTestLib 'new_schema'; +use MySchema; + +my $form = HTML::FormFu->new; + +$form->populate({ + elements => [ + { + name => 'band', + }, + { + type => 'Block', + nested_name => 'manager', + elements => { + name => 'name', + } + } + ] +}); + +my $schema = new_schema(); + +my $rs = $schema->resultset('Band'); +my $band = $rs->new_result({}); + +$form->process({ band => 'The Foobars', 'manager.name' => 'Mr Foo' }); + +$form->model('DBIC')->update($band); + +$band->discard_changes; + +is($band->band, 'The Foobars'); +is($band->manager->name, 'Mr Foo'); + +done_testing; \ No newline at end of file Index: t/lib/MySchema/Band.pm =================================================================== --- t/lib/MySchema/Band.pm (revision 1672) +++ t/lib/MySchema/Band.pm (working copy) @@ -16,7 +16,7 @@ __PACKAGE__->set_primary_key("id"); -__PACKAGE__->belongs_to( manager => 'MySchema::Manager', 'id' ); +__PACKAGE__->belongs_to( manager => 'MySchema::Manager' ); __PACKAGE__->has_many( user_bands => 'MySchema::UserBand', 'band' ); Index: lib/HTML/FormFu/Model/DBIC.pm =================================================================== --- lib/HTML/FormFu/Model/DBIC.pm (revision 1672) +++ lib/HTML/FormFu/Model/DBIC.pm (working copy) @@ -477,6 +477,7 @@ } elsif ( defined $block && ref $params eq 'HASH' ) { + $dbic->$rel(undef) unless($dbic->$rel); my $target = $dbic->find_related( $rel, {} ); if ( !defined $target && grep { length $_ } values %$params ) { @@ -492,6 +493,10 @@ nested_base => $rel, from => $dbic->result_class, } ); + unless($dbic->$rel) { + $dbic->$rel($target); + $dbic->update; + } } elsif ( defined $multi_value ) { # belongs_to, has_one or might_have relationship