[DDC-116] array_combine error when using combined Primary Key Created: 05/Nov/09  Updated: 14/Jun/10  Resolved: 06/Nov/09

Status: Closed
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: None
Fix Version/s: 2.0-ALPHA3
Security Level: All

Type: Bug Priority: Critical
Reporter: Nico Kaiser Assignee: Roman S. Borschel
Resolution: Fixed Votes: 0
Labels: None

Attachments: Text File Assigned.php    

 Description   

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:

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

Entities:
http://pastebin.com/d51e021e2

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



 Comments   
Comment by Nico Kaiser [ 06/Nov/09 ]

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

Comment by Roman S. Borschel [ 06/Nov/09 ]

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

Comment by Nico Kaiser [ 06/Nov/09 ]

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.

Comment by Roman S. Borschel [ 06/Nov/09 ]

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;
 }
Comment by Roman S. Borschel [ 06/Nov/09 ]

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

Comment by Roman S. Borschel [ 06/Nov/09 ]

Should be fixed now.

Generated at Wed Apr 23 11:49:44 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.