0
データベースに2つのテーブルがあり、製品を追加するときに両方のテーブルに挿入する必要があります。私はトランザクションを使用する必要があると思うが、私はCakePHP、SQLなどの学習段階にいるので、私は立ち往生している。CakePHPでトランザクションを使用する
それらは私のテーブル
products(id, name, description, price)
images(id, path, alt, product_id)
であり、製品モデル内のメソッドは次のようになります。
function newProduct($product, $image){
if(!empty($product) && !empty($image)){
$dataSource = $this->getDataSource();
$dataSource->begin($this);
if($this->save($product)){
ClassRegistry::init('Image');
$Image = new Image();
$Image->product_id = $this->id;
//I'm stuck here, how to save ??
return $dataSource->commit($this);
}
$dataSource->rollback($this);
}
return false;
}