DDC-116: array_combine error when using combined Primary Key #146

Closed
opened 2026-01-22 12:28:33 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 5, 2009).

Jira issue originally created by user nicokaiser:

I use a combined Primary Key for a User's Phonenumber entity (to match our existing DB model). The key is combined from a "Type" field and a "userId" field that references the User table.

To mark the (referenced!) userId field and the type field as PK, I need to add "userId" to the model (adding @Id to User does not work). This works well when generating Users and Phonenumbers - but the delete command breaks:

{panel}
PHP Warning: array_combine(): Both parameters should have an equal number of elements in ..../lib/Doctrine/ORM/Persisters/StandardEntityPersister.php on line 274
PHP Catchable fatal error: Argument 2 passed to Doctrine\DBAL\Connection::delete() must be an array, boolean given, called in ..../lib/Doctrine/ORM/Persisters/StandardEntityPersister.php on line 275 and defined in ..../lib/Doctrine/DBAL/Connection.php on line 372
{panel}

Entities:
http://pastebin.com/d51e021e2

Test code:
http://pastebin.com/m51d1f497

Originally created by @doctrinebot on GitHub (Nov 5, 2009). Jira issue originally created by user nicokaiser: I use a combined Primary Key for a User's Phonenumber entity (to match our existing DB model). The key is combined from a "Type" field and a "userId" field that references the User table. To mark the (referenced!) userId field and the type field as PK, I need to add "userId" to the model (adding @Id to User does not work). This works well when generating Users and Phonenumbers - but the delete command breaks: {panel} PHP Warning: array_combine(): Both parameters should have an equal number of elements in ..../lib/Doctrine/ORM/Persisters/StandardEntityPersister.php on line 274 PHP Catchable fatal error: Argument 2 passed to Doctrine\DBAL\Connection::delete() must be an array, boolean given, called in ..../lib/Doctrine/ORM/Persisters/StandardEntityPersister.php on line 275 and defined in ..../lib/Doctrine/DBAL/Connection.php on line 372 {panel} Entities: http://pastebin.com/d51e021e2 Test code: http://pastebin.com/m51d1f497
admin added the Bug label 2026-01-22 12:28:33 +01:00
admin closed this issue 2026-01-22 12:28:33 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 6, 2009):

Comment created by nicokaiser:

I attached a patch for Doctrine\Orm\Id\Assigned, there seems to be a runaway line which makes the class add each element twice...

@doctrinebot commented on GitHub (Nov 6, 2009): Comment created by nicokaiser: I attached a patch for Doctrine\Orm\Id\Assigned, there seems to be a runaway line which makes the class add each element twice...
Author
Owner

@doctrinebot commented on GitHub (Nov 6, 2009):

Comment created by romanb:

Whoops. Thanks for finding this! Does it fix this issue? I will need to add a testcase to the suite.

@doctrinebot commented on GitHub (Nov 6, 2009): Comment created by romanb: Whoops. Thanks for finding this! Does it fix this issue? I will need to add a testcase to the suite.
Author
Owner

@doctrinebot commented on GitHub (Nov 6, 2009):

Comment created by nicokaiser:

Does not entirely fix it: if the $value is empty, too few elements are added again.
Need to remove the "if (isset($value)) {" clause. I'll attach the fixed Assigned.php.

@doctrinebot commented on GitHub (Nov 6, 2009): Comment created by nicokaiser: Does not entirely fix it: if the $value is empty, too few elements are added again. Need to remove the "if (isset($value)) {" clause. I'll attach the fixed Assigned.php.
Author
Owner

@doctrinebot commented on GitHub (Nov 6, 2009):

Comment created by romanb:

I think the isset() is correct. That way the $identifier array remains empty if the PK is null and later if ( ! $identifier) evaluates to false on the empty array and raises the exception. If we remove the isset() we would "accept" PKs with null values. But it might be better to do:

 if (!isset($value)) {
        throw ORMException::entityMissingAssignedId($entity);
  } else {
         $identifier[] = $value;
 }
@doctrinebot commented on GitHub (Nov 6, 2009): Comment created by romanb: I think the isset() is correct. That way the $identifier array remains empty if the PK is null and later if ( ! $identifier) evaluates to false on the empty array and raises the exception. If we remove the isset() we would "accept" PKs with null values. But it might be better to do: ``` if (!isset($value)) { throw ORMException::entityMissingAssignedId($entity); } else { $identifier[] = $value; } ```
Author
Owner

@doctrinebot commented on GitHub (Nov 6, 2009):

Comment created by romanb:

I will fix this and add some new tests for it.

@doctrinebot commented on GitHub (Nov 6, 2009): Comment created by romanb: I will fix this and add some new tests for it.
Author
Owner

@doctrinebot commented on GitHub (Nov 6, 2009):

Comment created by romanb:

Should be fixed now.

@doctrinebot commented on GitHub (Nov 6, 2009): Comment created by romanb: Should be fixed now.
Author
Owner

@doctrinebot commented on GitHub (Nov 6, 2009):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Nov 6, 2009): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/b9db7c4a3b7ef6902974

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/b9db7c4a3b7ef6902974 - [10143_Assigned.php](https://gist.github.com/b9db7c4a3b7ef6902974#file-10143_Assigned-php)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#146