我使用CakePHP为dynamoDB表创建了一个新的Datasource。 创建,删除和更新工作查找除了从模型创建时返回的数组。
我的表中的主键名为 device_id ,这是我在创建新条目时获得的结果:
$dataReturned = $deviceInfosModel->save($data, true, array_keys($data));
debug($dataReturned);
array(
'DeviceInfos' => array(
'device_id' => false,
'shop_id' => 123,
'user_id' => 1234,
)
)
虽然创建了条目,但主键在返回的数组中始终设置为false。我开始深入研究cakePHP的代码,发现在Model中有一行在创建时将主键设置为false。 https://github.com/cakephp/cakephp/blob/master/lib/Cake/Model/Model.php#L1857 我的主键是随机生成的,带有唯一的哈希值。
有没有办法避免这种情况?我会很感激任何提示。
dynamoDB表如下:
name:device_infos 主要ID'device_id'(字符串),user_id,shop_id
模型看起来像这样:
<?php
class DeviceInfos extends AppModel {
public $useDbConfig = 'deviceInfos';
public $useTable = 'device_infos';
public $primaryKey = 'device_id';
protected $_schema = array(
'device_id' => array(
'type' => 'string',
'key' => 'primary',
'length' => 128,
),
'user_id' => array(
'type' => 'integer',
'length' => 255,
),
'shop_id' => array(
'type' => 'integer',
),
'timestamp' => array(
'type' => 'integer',
),
'timestampRange' => array(
'type' => 'integer',
)
);
}