Leave db->cacheSources unaltered.

When a model uses cacheSources = false, it should not have side effects
on the datasource.

Fixes #2364
This commit is contained in:
mark_story 2013-11-19 15:06:55 -05:00
parent cc94026f7e
commit 99fd6e40fe

View file

@ -1125,10 +1125,13 @@ class Model extends Object implements CakeEventListener {
public function setSource($tableName) {
$this->setDataSource($this->useDbConfig);
$db = ConnectionManager::getDataSource($this->useDbConfig);
$db->cacheSources = ($this->cacheSources && $db->cacheSources);
if (method_exists($db, 'listSources')) {
$restore = $db->cacheSources;
$db->cacheSources = $this->cacheSources;
$sources = $db->listSources();
$db->cacheSources = $restore;
if (is_array($sources) && !in_array(strtolower($this->tablePrefix . $tableName), array_map('strtolower', $sources))) {
throw new MissingTableException(array(
'table' => $this->tablePrefix . $tableName,