【发布时间】:2016-08-17 03:38:03
【问题描述】:
使用 CakePHP 3.3,我有一个只包含主键的表。这被用作一个序列。在 CakePHP 中,我插入一个没有数据的行并生成一个新行。
蛋糕 2.7
class Identity extends AppModel {
function nextVal() {
$data = [];
$this->create();
$this->save($data);
return $this->id;
}
}
我试图在 CakePHP 3.3 中复制这种行为,但它并没有达到我的预期。
CakePHP 3.3
class IdentityTable extends Table
{
public function generate() {
$identity = $this->newEntity();
if ( $this->save($identity) ) {
// The $ccn entity contains the id now
\Cake\Log\Log::debug(__METHOD__. ' success');
return $identity->id;
}
\Cake\Log\Log::debug(__METHOD__. ' failed');
return false;
}
//
public function initialize(array $config)
{
parent::initialize($config);
$this->table('identity');
$this->displayField('identityId');
$this->primaryKey('identityId');
}
}
MySQL 对此非常满意:
INSERT INTO `identity` () VALUES()
我在想 CakePHP 3.x ORM 看到我没有插入任何东西,它会在保存时放弃。
CakePHP 3 中有没有办法插入没有数据的行?
【问题讨论】:
标签: mysql cakephp cakephp-3.0