Browse Source

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
mark_story 13 years ago
parent
commit
62660c6706
2 changed files with 3 additions and 2 deletions
  1. 1 2
      lib/Cake/Model/ConnectionManager.php
  2. 2 0
      lib/Cake/Model/Model.php

+ 1 - 2
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])) {

+ 2 - 0
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]);
 		}