From 62660c67069f54b92f302cd2f0eff6ef075e3b2e Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 21 Apr 2013 21:15:44 -0400 Subject: [PATCH] Re-assign $db after beforeSave. This allows model/behavior methods to change the datasource in the beforeSave callback. If you use drivers from different SQL platforms things will go very poorly. Fixes #3606 --- lib/Cake/Model/ConnectionManager.php | 3 +-- lib/Cake/Model/Model.php | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/ConnectionManager.php b/lib/Cake/Model/ConnectionManager.php index 4437ec435..eaa62bde6 100644 --- a/lib/Cake/Model/ConnectionManager.php +++ b/lib/Cake/Model/ConnectionManager.php @@ -86,8 +86,7 @@ class ConnectionManager { } if (!empty(self::$_dataSources[$name])) { - $return = self::$_dataSources[$name]; - return $return; + return self::$_dataSources[$name]; } if (empty(self::$_connectionsEnum[$name])) { diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 61952a13d..035a062ef 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1689,6 +1689,8 @@ class Model extends Object implements CakeEventListener { } } + $db = $this->getDataSource(); + if (empty($this->data[$this->alias][$this->primaryKey])) { unset($this->data[$this->alias][$this->primaryKey]); }