Preventing datasource creationa and access on models having $useTable = false;

This commit is contained in:
Jose Lorenzo Rodriguez 2012-01-21 14:03:11 -04:30
parent bc689151a4
commit 6aa08b5f52
2 changed files with 13 additions and 1 deletions

View file

@ -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) {

View file

@ -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());
}
}