Skip to content

Commit

Permalink
Merge pull request #2367 from cakephp/issue-2364
Browse files Browse the repository at this point in the history
Leave db->cacheSources unaltered.

Fixes #2364
  • Loading branch information
markstory committed Nov 19, 2013
2 parents cc94026 + 1be40d5 commit 7fdf17e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -1125,10 +1125,13 @@ protected function _generateAssociation($type, $assocKey) {
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 = ($restore && $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,
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Test/Case/Model/ModelIntegrationTest.php
Expand Up @@ -155,17 +155,17 @@ public function testPkInHabtmLinkModelArticleB() {
}

/**
* Tests that $cacheSources can only be disabled in the db using model settings, not enabled
* Tests that $cacheSources is restored despite the settings on the model.
*
* @return void
*/
public function testCacheSourcesDisabling() {
public function testCacheSourcesRestored() {
$this->loadFixtures('JoinA', 'JoinB', 'JoinAB', 'JoinC', 'JoinAC');
$this->db->cacheSources = true;
$TestModel = new JoinA();
$TestModel->cacheSources = false;
$TestModel->setSource('join_as');
$this->assertFalse($this->db->cacheSources);
$this->assertTrue($this->db->cacheSources);

$this->db->cacheSources = false;
$TestModel = new JoinA();
Expand Down

0 comments on commit 7fdf17e

Please sign in to comment.