From 8526e8bb02fff334d7b53b6d1524f19224e4ca51 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sat, 3 Aug 2013 10:48:59 +0300 Subject: [PATCH] fix record insertion --- ipf/orm/connection.php | 2 +- ipf/orm/connection/unitofwork.php | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) 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); -- 2.49.0