Skip to content

Commit

Permalink
No need to get the datasource if column is defined in schema. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
ceeram committed Jan 21, 2015
1 parent c5c9c3a commit 9ce75e6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -1428,8 +1428,12 @@ public function getColumnTypes() {
* @return string Column type
*/
public function getColumnType($column) {
$db = $this->getDataSource();
$cols = $this->schema();
if (isset($cols[$column]) && isset($cols[$column]['type'])) {
return $cols[$column]['type'];
}

$db = $this->getDataSource();
$model = null;

$startQuote = isset($db->startQuote) ? $db->startQuote : null;
Expand Down
13 changes: 13 additions & 0 deletions lib/Cake/Test/Case/Model/ModelIntegrationTest.php
Expand Up @@ -2497,4 +2497,17 @@ public function testSchemaNoDB() {
$model->expects($this->never())->method('getDataSource');
$this->assertEmpty($model->schema());
}

/**
* Tests that calling getColumnType() on a model that is not supposed to use a table
* does not trigger any calls on any datasource
*
* @return void
*/
public function testGetColumnTypeNoDB() {
$model = $this->getMock('Example', array('getDataSource'));
$model->expects($this->never())->method('getDataSource');
$result = $model->getColumnType('filefield');
$this->assertEquals('string', $result);
}
}
31 changes: 31 additions & 0 deletions lib/Cake/Test/Case/Model/models.php
Expand Up @@ -5048,3 +5048,34 @@ public function beforeValidate($options = array()) {
}

}

/**
* Example class
*
* @package Cake.Test.Case.Model
*/
class Example extends AppModel {

/**
* useTable property
*
* @var string
*/
public $useTable = false;

/**
* schema property
*
* @var array
*/
protected $_schema = array(
'filefield' => array(
'type' => 'string',
'length' => 254,
'default' => null,
'null' => true,
'comment' => null
),
);

}

0 comments on commit 9ce75e6

Please sign in to comment.