mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Preventing datasource creationa and access on models having $useTable = false;
This commit is contained in:
parent
bc689151a4
commit
6aa08b5f52
2 changed files with 13 additions and 1 deletions
|
@ -1219,7 +1219,7 @@ class Model extends Object {
|
|||
* @return array Array of table metadata
|
||||
*/
|
||||
public function schema($field = false) {
|
||||
if (!is_array($this->_schema) || $field === true) {
|
||||
if ($this->useTable !== false && (!is_array($this->_schema) || $field === true)) {
|
||||
$db = $this->getDataSource();
|
||||
$db->cacheSources = ($this->cacheSources && $db->cacheSources);
|
||||
if (method_exists($db, 'describe') && $this->useTable !== false) {
|
||||
|
|
|
@ -2106,4 +2106,16 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
ConnectionManager::drop('mock');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that calling schema() on a model that is not supposed to use a table
|
||||
* does not trigger any calls on any datasource
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
public function testSchemaNoDB() {
|
||||
$model = $this->getMock('Article', array('getDataSource'));
|
||||
$model->useTable = false;
|
||||
$model->expects($this->never())->method('getDataSource');
|
||||
$this->assertEmpty($model->schema());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue