我必须将字段 cpf_formatado 添加到我的数据库视图(SQL Server) vwComissionarios 。但是CakePHP模型没有获取这个新领域,这让我发疯了。
此打印显示该字段已在数据库视图上正确创建:
但是,由于某种原因,CakePHP不会获取该字段,而我正在使用相同的查询。这是一个测试:
public function infoGestor($id = null){
$this->layout = 'ajax';
$this->loadModel('Comissionario');
debug($this->Comissionario->query("select cpf_formatado from vwcomissionarios")); die();
}
最后,这是Comissionario模型:
<?php
App::uses('AppModel', 'Model');
/**
* Comissionario Model
*
*/
class Comissionario extends AppModel {
public $useTable = 'vwComissionarios';
/**
* Primary key field
*
* @var string
*/
public $primaryKey = 'id';
/**
* Display field
*
* @var string
*/
public $displayField = 'nome';
/**
* Validation rules
*
* @var array
*/
public $hasMany = array(
'VwComissionarioContato' => array('className' => 'VwComissionarioContato',
'foreignKey' => 'comissionarios_id',
'conditions' => array(),
'fields' => array(),
'order' => '',
),
'ComissionarioBanco' => array('className' => 'ComissionarioBanco',
'foreignKey' => 'comissionarios_id',
'conditions' => array(),
'fields' => array(),
'order' => '',
),
);
}