Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-116

array_combine error when using combined Primary Key

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-ALPHA3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      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

        Activity

        Nico Kaiser created issue -
        Hide
        Nico Kaiser added a comment -

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

        Show
        Nico Kaiser added a comment - I attached a patch for Doctrine\Orm\Id\Assigned, there seems to be a runaway line which makes the class add each element twice...
        Nico Kaiser made changes -
        Field Original Value New Value
        Attachment Fix-composite-Id-bug.patch [ 10142 ]
        Hide
        Roman S. Borschel added a comment -

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

        Show
        Roman S. Borschel added a comment - Whoops. Thanks for finding this! Does it fix this issue? I will need to add a testcase to the suite.
        Hide
        Nico Kaiser added a comment -

        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.

        Show
        Nico Kaiser added a comment - 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.
        Nico Kaiser made changes -
        Attachment Assigned.php [ 10143 ]
        Nico Kaiser made changes -
        Attachment Fix-composite-Id-bug.patch [ 10142 ]
        Hide
        Roman S. Borschel added a comment - - edited

        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;
         }
        
        Show
        Roman S. Borschel added a comment - - edited 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; }
        Hide
        Roman S. Borschel added a comment -

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

        Show
        Roman S. Borschel added a comment - I will fix this and add some new tests for it.
        Roman S. Borschel made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Roman S. Borschel added a comment -

        Should be fixed now.

        Show
        Roman S. Borschel added a comment - Should be fixed now.
        Roman S. Borschel made changes -
        Status In Progress [ 3 ] Closed [ 6 ]
        Fix Version/s 2.0-ALPHA3 [ 10029 ]
        Resolution Fixed [ 1 ]
        Roman S. Borschel made changes -
        Component/s ORM [ 10012 ]
        Component/s DBAL [ 10011 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 10343 ] jira-feedback [ 15465 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15465 ] jira-feedback2 [ 17329 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17329 ] jira-feedback3 [ 19586 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-116, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Nico Kaiser
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: