[html-formfu] Model::DBIC and belongs_to rels

Peter Shangov pshangov at yahoo.com
Fri Apr 8 14:32:52 GMT 2011


Hi,

There are a couple of issues with updating belongs_to relationships via Model::DBIC that I have been trying to debug.

1. Required belongs_to rels:

I sent an explanation and a patch here:

https://github.com/fireartist/HTML-FormFu-Model-DBIC/pull/3

Carl, the repo log says that you have tried to merge this but tests failed. Can you tell me what exactly failed because everything seems to work fine on my machine (tested with both the moosified and the non-moosified versin of FF).

Anyway, I will probably need to do some further work on this one since I would like to have a solution that does not mess with DBIx::Class internals…

2. PosgreSQL fails on new_related for belongs_to rels

This seems to be a problem with DBIx::Class itself and I have sent an email to the dbix-class mailing list:

http://lists.scsys.co.uk/pipermail/dbix-class/2011-April/009852.html

This leads to failures any time you try to update belongs_to relationships with PostgreSQL:

https://gist.github.com/909922

I have experimented with a few workarounds and the only one that seems to work without breaking the test suite is to remove the filtering for required relationships in the fix for item 1 above and insert all belongs to relationships first (before the main row). 

3. Empty belongs_to rels

I have yet to test this thoroughly, but the problems seems to be that if the form contains a block with a nested_name corresponding to a belongs_to relationship, and the user submits empty values for all fields within this block, Model::DBIC::update() will still attempt to create a new related row with just default values from the database. I think this does not happen for other types of relationships, and _can_insert_new_row() seems to be doing checks for this (have not tested  yet …). I will look into this next week, but I would appreciate any guidance as to whether this is expected behavior and how I should go about addressing it.

Ideally I imagine there being an “ignore_if_empty” option for blocks too, so that users can choose whether they want the defaults from the database or skip the related row altogether.

Cheers,




More information about the HTML-FormFu mailing list