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

HTML::FormHandler::TraitFor::Model::DBIC bungles objects with multiple primary keys #16

Open
karenetheridge opened this issue Nov 29, 2016 · 0 comments

Comments

@karenetheridge
Copy link

karenetheridge commented Nov 29, 2016

in HTML::FormHandler::TraitFor::Model::DBIC::set_item, the primary key(s) are used to calculate the $item_id, and then the $item_id is tested for truthiness. This check is incorrect for schema objects with multiple primary keys, as the item_id will always be true ([ { key1 => ..., key2 => ..., } ]). Calling $self->item_id($item_id) when the primary keys are undefined then results in an uninitialized warning in set_item_id.

I think this is the right change to make (I'm not sure how to test it):

--- a/lib/HTML/FormHandler/TraitFor/Model/DBIC.pm
+++ b/lib/HTML/FormHandler/TraitFor/Model/DBIC.pm
@@ -563,7 +563,10 @@ sub set_item {
     }
     elsif ( @primary_columns > 1 ) {
         my @pks = map { $_ => $item->get_column($_) } @primary_columns;
-        $item_id = [ { @pks }, { key => 'primary' } ];
+        # only set item_id if all PK columns are set
+        if (not grep { !$_ } @pks) {
+            $item_id = [ { @pks }, { key => 'primary' } ];
+        }
     }
     if ($item_id) {
         $self->item_id($item_id);
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

No branches or pull requests

1 participant