Doctrine 1
  1. Doctrine 1
  2. DC-205

Problem with serial fields on PostgreSQL

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.2.0-BETA1
    • Fix Version/s: 1.2.0-BETA2
    • Component/s: None
    • Labels:
      None
    • Environment:
      PHP 5.2.3
      PostgreSQL 8.1

      Description

      When a new record is inserted into a table with an autoincrement primary key, the function Doctrine_Connection_UnitOfWork::processSingleInsert is called with the record to insert as parameter.

      In Doctrine 1.1.x (http://trac.doctrine-project.org/browser/branches/1.1/lib/Doctrine/Connection/UnitOfWork.php#L590) this method was the responsible for getting the new ID value from the sequence, and with this value, it MODIFIED THE ARRAY OF FIELD VALUES to be inserted into the table.

      Now this is done at a protected method named _assignSequence (http://trac.doctrine-project.org/browser/branches/1.2/lib/Doctrine/Connection/UnitOfWork.php#L629) which assigns the identifier to the record, but DOES NOT MODIFY THE ARRAY OF VALUES to be send to the database for the insert so when my db receive a null value for the ID column, generate a new one from the sequence.

      The result is that the record gets an identifier which is different from the one that it really has on the database.

      An example: on a db with a table 'foo' with two columns, 'id' and 'name', and a sequence called 'foo_id_seq' with a value of 6, when I try to insert a record with a named 'bar', the function $this->conn->insert($table, $fields); at http://trac.doctrine-project.org/browser/branches/1.1/lib/Doctrine/Connection/UnitOfWork.php#L595 receive as parameters 'foo' and array('id' =>7, 'name' =>'bar')

      In Doctrine 1.2 the function at http://trac.doctrine-project.org/browser/branches/1.2/lib/Doctrine/Connection/UnitOfWork.php#L630 recevie as parameters 'foo' and array('name' =>'bar')

      (Sorry for my poor English)

        Activity

        Hide
        Antonio J. Garcia Lagar added a comment -
        Show
        Antonio J. Garcia Lagar added a comment - This error is a consecuence of the changeset 6635 ( http://trac.doctrine-project.org/changeset/6635/branches/1.2/lib/Doctrine/Connection/UnitOfWork.php )
        Hide
        Jonathan H. Wage added a comment -

        Thanks for the ticket. I committed a fix that will be in BETA2. Could you test and confirm that it fixes the issue?

        Show
        Jonathan H. Wage added a comment - Thanks for the ticket. I committed a fix that will be in BETA2. Could you test and confirm that it fixes the issue?

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Antonio J. Garcia Lagar
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: