0
目前,我無法手動將記錄保存到HABTM連接表。我有一張表,users_products
,並希望將有關訂單(大小,數量,顏色等等)的所有其他信息保存到此連接表中,而不是另外創建一個表。如何將其他信息保存到CakePHP HABTM連接表?
用戶$ hasAndBelongsTo產品
我的用戶控制器代碼這樣做:
Configure::write('debug', 0);
//adds product to cart
$this->layout = ""; //async
$user = $this->User->find('first',array('conditions'=>array('User.id'=>$this->Auth->user("id"))));
$data['User'] = $user['User'];
$addition = array('user_id' => $this->Auth->user("id"),
'product_id' => $id,
'size' => $size,
'quantity' => $quantity);
$data['Product'][] = $addition;
$this->User->create();
if ($this->User->saveAll($data)) {
echo $data['User']['amount_in_cart'];
} else {
echo $curr_cart_amt['User']['amount_in_cart'];
}
不幸的是,這增加了一個新的記錄到數據庫中,並清除出整個連接表,而這樣做。有任何想法嗎?
真棒,謝謝!這正是我所期待的。 – Nick 2011-03-30 13:46:25