Hi all,
I was working on a fix for a strange issue where H::FF::M::DBIC will attempt to
create an empty related row when no values were submitted for that
relationship, and while trying to reproduce it in a test I stumbled upon a
possible bug that might mess up with the saving of nested blocks (I wanted to
add an ignore_if_empty option for blocks, hence the name of the test below).
You will need to get a copy of my fork and switch to the ignore-if-empty-block
branch:
git clone git://github.com/pshangov/HTML-FormFu-Model-DBIC.git
git checkout ignore-if-empty-block
And then have a look at t\update\ignore-if-empty-block.t
and t\update\ignore-if-empty-block.yml.
In short, if I try to process my form with the following arguments:
# resulset is MySchema::User, has_many 'addresses'
'name' => 'Peter',
'addresses_counter' => '1',
'addresses_1.address' => '1 Baker Street',
'addresses_1.id' => '',
'addresses_1.city.name' => 'London',
the 'city' relationship will be ignored and address.city_id' will be undef.
This happens because H::FF::M::DBIC::_save_relationships does the following:
# $rel is 'city'
my $params = $form->param($rel); # undef, do not save anything
It seems this will fail to fetch parameters for any element with a
'nested_name' that is not a direct child of the top-level form. Curiously, I
can get it to work with the following trick:
# Add fake relationship via 'city.id' (the form needs to be modified too)
'name' => 'Peter',
'city.id' => 'whatever'
'addresses_counter' => '1',
...
my $params = $form->param($rel); # { id => 'whatever' }, so proceed with
saving addresses.city
# address.city_id is now correctly set to '1'
I am not really sure how I should fix that. What is the correct way to fetch
the parameters for a relationship that is nested more than one level deep?
Cheers,
--
Peter
_______________________________________________
HTML-FormFu mailing list
[email protected]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu