mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Merge pull request #2367 from cakephp/issue-2364
Leave db->cacheSources unaltered. Fixes #2364
This commit is contained in:
commit
7fdf17e43e
2 changed files with 7 additions and 4 deletions
|
@ -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 = ($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,
|
||||
|
|
|
@ -155,17 +155,17 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
|
Loading…
Add table
Reference in a new issue