diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index a79ad39750a..5c6827b7f38 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1219,7 +1219,7 @@ public function deconstruct($field, $data) { * @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) { diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index 5f94c88d5aa..add35893b00 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -2106,4 +2106,16 @@ public function testModelPrefixFromDatasource() { 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()); + } }