mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
No need to get the datasource if column is defined in schema. Fixes #5712
This commit is contained in:
parent
c5c9c3ac42
commit
9ce75e6fd6
3 changed files with 49 additions and 1 deletions
|
@ -1428,8 +1428,12 @@ class Model extends Object implements CakeEventListener {
|
||||||
* @return string Column type
|
* @return string Column type
|
||||||
*/
|
*/
|
||||||
public function getColumnType($column) {
|
public function getColumnType($column) {
|
||||||
$db = $this->getDataSource();
|
|
||||||
$cols = $this->schema();
|
$cols = $this->schema();
|
||||||
|
if (isset($cols[$column]) && isset($cols[$column]['type'])) {
|
||||||
|
return $cols[$column]['type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = $this->getDataSource();
|
||||||
$model = null;
|
$model = null;
|
||||||
|
|
||||||
$startQuote = isset($db->startQuote) ? $db->startQuote : null;
|
$startQuote = isset($db->startQuote) ? $db->startQuote : null;
|
||||||
|
|
|
@ -2497,4 +2497,17 @@ class ModelIntegrationTest extends BaseModelTest {
|
||||||
$model->expects($this->never())->method('getDataSource');
|
$model->expects($this->never())->method('getDataSource');
|
||||||
$this->assertEmpty($model->schema());
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5048,3 +5048,34 @@ class CustomArticle extends AppModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue