我試圖用CakePHP的SaveAll()方法更新記錄,但是它增加了新行而不是更新它。saveAll()插入新行而不是更新
我的模型如下:商店hasOne地圖
class Store extends AppModel {
var $name = 'Store';
var $hasOne = array(
'Map' => array(
'className' => 'Map',
'foreignKey' => 'store_id',
'dependent' => true,
'exclusive' => true
)
);
}
我的編輯形式所具有的存儲ID(隱藏字段)告訴CakePHP的只更新特定的記錄。
<?php echo $this->Form->input('Store.id'); ?>
<?php echo $this->Form->input('Store.name', array('label' => 'Store name', 'required')); ?>
<?php echo $this->Form->input('Map.latlng', array('label' => 'Map location', 'required')); ?>
我在Store控制器中的編輯方法如下。
if ($this->Store->saveAll($this->data)) {
$this->Session->setFlash('Store has been updated.');
$this->redirect(array('controller' => 'store', 'action' => 'admin_index'));
}
每當我編輯一個存儲,商店名稱更新正常,但CakePHP不斷在Map表上插入一個新行。
我在這裏錯過了什麼嗎?由於
其他信息
我的調試($這個 - >數據)如下
Array
(
[Store] => Array
(
[id] => 52
[name] => Sena The Accessorizer
)
[Map] => Array
(
[latlng] => 3.1580681, 101.7126311
)
)
顯示'$ this-> data'的調試 – Dunhamzzz 2012-01-31 15:11:18
@Dunhamzzz問題已更新。謝謝 – 2012-01-31 15:22:07
@John - 什麼是你的Form->創建? – Dave 2012-01-31 15:42:46