我试图用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