Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for creating required belongs_to relationships #3

Closed
wants to merge 1 commit into from

Conversation

pshangov
Copy link
Contributor

@pshangov pshangov commented Mar 2, 2011

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.:

_save_columns( ... );
$dbic->update_or_insert;
_save_relationships( ... );

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

@pshangov
Copy link
Contributor Author

pshangov commented Mar 2, 2011

Actually I just discovered there is a further problem specific to Pg (t/update/belongs_to_create.t fails if run under Pg), will send an updated patch soon ...

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant