【发布时间】:2019-06-05 04:28:30
【问题描述】:
我有两个具有同一张表的数据库。
db1.wafer_types 表:-
ID waferType name
1071 req_1 req_1_name
1072 req_2 req_2_name
1073 req_3 req_3_name
db2.wafer_types 表:-
ID wafer_type_id waferType name
1 1071 req_1 req_1_name
2 1072 req_2 req_2_name
3 1073 req_3 req_3_name
模型(WaferTypesTable)
class WaferTypesTable extends Table {
public function initialize(array $config) {
parent::initialize($config);
$this->setTable('wafer_types');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
}
}
实体(晶圆类型)
class WaferType extends Entity
{
protected $_accessible = [
'*' => true,
'id' => false
];
}
控制器功能:-
public function waferTypeHistory($id,$userid){
$waferType = $this->WaferTypes->find()->where(['id'=>$id])->hydrate(false)->toArray();
$connection = ConnectionManager::get('default_history');
$this->WaferTypes->setConnection($connection);
$waferTypeHistory = $this->WaferTypes->newEntity();
$waferTypeHistory = $this->WaferTypes->patchEntity($waferTypeHistory, $waferType[0]);
$waferTypeHistory->wafer_type_id = $id;
$this->WaferTypes->save($waferTypeHistory);
return true;
}
在 db2.wafer_types 表中成功插入数据。但是wafer_type_id 归档得到值'0'。我给它赋值,但它总是得到值'0'。 知道为什么它每次都获得价值'0'。
【问题讨论】:
标签: cakephp orm cakephp-3.0