現在、レコードを手動でHABTM結合テーブルに保存できません。私はテーブルusers_products
を持っていて、別のテーブルを作成するのではなく、この結合テーブルに注文に関するすべての追加情報(サイズ、数量、色など)を保存したいと思います。追加情報をCakePHP HABTM Join Tableに保存するにはどうしたらいいですか?
ユーザーの$ 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