【发布时间】:2014-01-14 21:01:00
【问题描述】:
我尝试使用“hasMany through”模型通过一个查询保存多个数据。 返回 $this->request->data 的值表明:
Array
(
[Order] => Array
(
[id] =>
[customer_id] => 4711
[orderDate] => Array
(
[month] => 01
[day] => 14
[year] => 2014
)
...
)
[ArticleOrder] => Array
(
[article_id] => Array
(
[0] => 2002
)
[quantity] => Array
(
[0] => 99
)
)
)
数组 [ArticleOrder] 尚未保存在数据库中。在我的控制器中,我尝试了 saveAll (yes deep => true)、saveMany、saveAssociated...
这里是控制器:
public function add() {
$this->set('customers', $this->Order->Customer->find('list')); //Auflösung der Schlüssel
//$this->set('articles', $this->Order->ArticleOrder->Article->find('list'));
if(!empty($this->request->data)) {
$this->Order->create();
pr($this->data);
if($this->Order->ArticleOrder->saveAll($this->request->data, array('deep' => true))) {
$this->Session->setFlash("Die Bestellung wurde gespeichert!");
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash('Die Bestellung konnte nicht gespeichert werden.');
}
}
}
请帮帮我……我很绝望……
来自德国的问候
【问题讨论】:
标签: php cakephp has-many-through