diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 6a794b09a90..72d4361b73a 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -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; diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index 839af667183..8f941b05921 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -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); + } } diff --git a/lib/Cake/Test/Case/Model/models.php b/lib/Cake/Test/Case/Model/models.php index a4ce60c91d2..de578d21879 100644 --- a/lib/Cake/Test/Case/Model/models.php +++ b/lib/Cake/Test/Case/Model/models.php @@ -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 + ), + ); + +}