Support for creating required belongs_to relationships #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Carl,
Currently HTML::FormFu::Model::DBIC::update() will fail on creating a new row that has a ‘belongs_to’ relationship whose foreign key in the table is set to ‘NOT NULL’. The reason is that update() first adds all simple columns, inserts the new record into the database and only then proceeds to any relationships, i.e.:
If $dbic has a belongs_to relationship ‘manager’ with foreign key ‘manager_id’, and manager_id is required, $dbic->update_or_insert will fail since manager_id is not populated until _save_relationships( ... ).
I have proposed a solution which identifies any such relationships and adds them to the new object before the first insert. All tests runs fine but I find the code in update() very difficult to follow and I am not sure if I have not introduced side effects which are not covered by the test suite.
Cheers,
Peter