Skip to content

Commit

Permalink
Preventing datasource creationa and access on models having $useTable…
Browse files Browse the repository at this point in the history
… = false;
  • Loading branch information
lorenzo committed Jan 21, 2012
1 parent bc68915 commit 6aa08b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions lib/Cake/Test/Case/Model/ModelIntegrationTest.php
Expand Up @@ -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());
}
}

0 comments on commit 6aa08b5

Please sign in to comment.