From: Andrey Kutejko Date: Sat, 3 Aug 2013 07:48:59 +0000 (+0300) Subject: fix record insertion X-Git-Tag: 0.5~89 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=8526e8bb02fff334d7b53b6d1524f19224e4ca51;p=ipf.git fix record insertion --- diff --git a/ipf/orm/connection.php b/ipf/orm/connection.php index e175652..1931761 100644 --- a/ipf/orm/connection.php +++ b/ipf/orm/connection.php @@ -702,7 +702,7 @@ abstract class IPF_ORM_Connection extends IPF_ORM_Configurable implements Counta return $this->getAttribute(IPF_ORM::ATTR_QUERY_CACHE); } - public function lastInsertId($table = null, $field = null) + public function lastInsertId() { return $this->getDbh()->lastInsertId(); } diff --git a/ipf/orm/connection/unitofwork.php b/ipf/orm/connection/unitofwork.php index 07fa260..301b5d7 100644 --- a/ipf/orm/connection/unitofwork.php +++ b/ipf/orm/connection/unitofwork.php @@ -399,17 +399,11 @@ class IPF_ORM_Connection_UnitOfWork extends IPF_ORM_Connection_Module $this->conn->insert($table, $fields); - if (empty($seq) && count($identifier) == 1 && $identifier[0] == $table->getIdentifier() && - $table->getIdentifierType() != IPF_ORM::IDENTIFIER_NATURAL) { - if (strtolower($this->conn->getDriverName()) == 'Pgsql') { - $seq = $table->getTableName() . '_' . $identifier[0]; - } - - $id = $this->conn->lastInsertId($seq); - - if ( ! $id) { + if (count($identifier) == 1 && $table->getIdentifierType() !== IPF_ORM::IDENTIFIER_NATURAL) { + $id = $this->conn->lastInsertId(); + if (!$id) throw new IPF_ORM_Exception("Couldn't get last insert identifier."); - } + $record->assignIdentifier($id); } else { $record->assignIdentifier(true);