From e70f45e1d6131457d976f0a699acb03f459f3d35 Mon Sep 17 00:00:00 2001 From: gwoo Date: Thu, 26 Jun 2008 17:24:16 +0000 Subject: [PATCH] fixes #4987, unable to delete by adding version compare and setting useAlias in DboMysql git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7268 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo/dbo_mysql.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 20f7b54fa..6d3ba63f9 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -97,6 +97,12 @@ class DboMysql extends DboSource { 'binary' => array('name' => 'blob'), 'boolean' => array('name' => 'tinyint', 'limit' => '1') ); +/** + * use alias for update and delete. Set to true if version >= 4.1 + * + * @var boolean + */ + var $__useAlias = true; /** * Connects to the database using options in the given configuration array. * @@ -121,6 +127,8 @@ class DboMysql extends DboSource { $this->setEncoding($config['encoding']); } + $this->__useAlias = (bool)version_compare(mysql_get_server_info($this->connection), "4.1", ">="); + return $this->connected; } /** @@ -251,6 +259,10 @@ class DboMysql extends DboSource { * @return array */ function update(&$model, $fields = array(), $values = null, $conditions = null) { + if (!$this->__useAlias) { + return parent::update(&$model, $fields, $values, $conditions); + } + if ($values == null) { $combined = $fields; } else { @@ -286,6 +298,9 @@ class DboMysql extends DboSource { * @return boolean Success */ function delete(&$model, $conditions = null) { + if (!$this->__useAlias) { + return parent::delete(&$model, $conditions); + } $alias = $this->name($model->alias); $table = $this->fullTableName($model); $joins = implode(' ', $this->_getJoins($model));