Good morning,

I'm having a problem with nested blocks not updating repeatable (has_many) records. I think it's a bug but could be a problem with my app. My form config looks like this:

elements:
    - type: Text
      name: username
    - type: Text
      name: password

    - type: Block
      nested_name: customer
      elements:
        - type: Text
          name: name_company
        - type: Hidden
          name: id

        - type: Hidden
          name: addr_count

        - type: Repeatable
          nested_name: addresses
          counter_name: addr_count
          model_config:
            empty_rows: 1
            new_rows_max: 1
          elements:
            - type: Hidden
              name: id
            - type: Text
              name: addr_street
              model_config:
                delete_if_empty: 1

The actual error is DBIC::Validation failure when updating the Address record. The validation is failing since all fields are empty. Fields are empty because _save_columns is getting elements from 'customer' block rather than 'addresses' (determined through lots of warn statements, below). If I remove the DBIC::Validation checks then all records (user/customer/address) are created as expected but the address record has blank fields.

My schema setup looks like this:

package Schema::Result::User;
...
__PACKAGE__->might_have( customer => 'Schema::Result::Customer', 'user_id');


package Schema::Result::Customer;
...
__PACKAGE__->has_many( addresses => 'Schema::Result::Address', 'customer_id');


package Schema::Result::Address;
...


Watching lots of warn statements I added to Model::DBIC I see things like:

doing update for: MyApp::Model::DBIC::User
doing save_columns for: MyApp::Model::DBIC::User
save_columns for: username
save_columns for: password

doing update for: MyApp::Model::DBIC::Customer
doing save_columns for: MyApp::Model::DBIC::Customer
save_columns for: name_company
save_columns for: id
save_columns for: addr_count

doing save_has_many for: MyApp::Model::DBIC::Customer
save_has_many - block for: customer.addresses_1.id
save_has_many - insert for: customer.addresses_1.id
insert_has_many - new_related for: addresses
save_has_many - update for: customer.addresses_1.id

doing update for: MyApp::Model::DBIC::Address
doing save_columns for: MyApp::Model::DBIC::Address
save_columns for: name_company
save_columns for: id
save_columns for: addr_count


And it's the last bit where _save_columns is getting a field/element list from the customer block rather than the address block.

I've had a look at the code for Model::DBIC but I can't really follow all the nested logic to work out how to fix it, or determine whether it's a problem with my app/config.

Any help or suggestions would be appreciated.

Thanks,
Charlie

--
    Charlie Garrison                   <char...@garrison.com.au>
    Garrison Computer Services      <http://www.garrison.com.au>
    PO Box 141
    Windsor NSW 2756  Australia             Ph:  +61 2 4579-0612

()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments

http://www.ietf.org/rfc/rfc1855.txt

_______________________________________________
HTML-FormFu mailing list
HTML-FormFu@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

Reply via email to