From 49ed8ede8eb5ff1f8266c98adfdd843cb8fd0d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Mon, 25 Oct 2010 19:45:46 -0430 Subject: [PATCH] Trucating tables in postgres now correctly resets the associated sequences --- .../model/datasources/dbo/dbo_postgres.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 32b89d80f..a58c1a077 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -221,10 +221,12 @@ class DboPostgres extends DboSource { ), 'length' => $length ); - if ($c->name == $model->primaryKey) { - $fields[$c->name]['key'] = 'primary'; - if ($fields[$c->name]['type'] !== 'string') { - $fields[$c->name]['length'] = 11; + if ($model instanceof Model) { + if ($c->name == $model->primaryKey) { + $fields[$c->name]['key'] = 'primary'; + if ($fields[$c->name]['type'] !== 'string') { + $fields[$c->name]['length'] = 11; + } } } if ( @@ -284,8 +286,14 @@ class DboPostgres extends DboSource { * @return boolean SQL TRUNCATE TABLE statement, false if not applicable. */ public function truncate($table, $reset = true) { + $table = $this->fullTableName($table, false); + if (!isset($this->_sequenceMap[$table])) { + $cache = $this->cacheSources; + $this->cacheSources = false; + $this->describe($table); + $this->cacheSources = $cache; + } if (parent::truncate($table)) { - $table = $this->fullTableName($table, false); if (isset($this->_sequenceMap[$table]) && $reset) { foreach ($this->_sequenceMap[$table] as $field => $sequence) { $this->_execute("ALTER SEQUENCE \"{$sequence}\" RESTART WITH 1");