diff --git a/lib/Doctrine/Connection/UnitOfWork.php b/lib/Doctrine/Connection/UnitOfWork.php index 6fd5cde3e..22817f8a0 100644 --- a/lib/Doctrine/Connection/UnitOfWork.php +++ b/lib/Doctrine/Connection/UnitOfWork.php @@ -320,15 +320,18 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen $id = $this->conn->sequence->nextId($seq); $name = $record->getTable()->getIdentifier(); $array[$name] = $id; + + $record->assignIdentifier($id); } $this->conn->insert($table->getTableName(), $array); - if (count($keys) == 1 && $keys[0] == $table->getIdentifier()) { - $id = $this->conn->getDBH()->lastInsertID(); + if (empty($seq) && count($keys) == 1 && $keys[0] == $table->getIdentifier()) { + $id = $this->conn->sequence->lastInsertId(); - if ( ! $id) + if ( ! $id) { $id = $table->getMaxIdentifier(); + } $record->assignIdentifier($id); } else {