From http://te.gd/wiki/291/update-two-models-with-one-view/
code สำหรับบันทึกข้อมูลหลายโมเดลที่สัมพันธ์กันแบบใช้ transaction
$transaction = Yii::app()->db->beginTransaction();
try {
$post = new Post;
$post->title = "test post 1";
if ($post->save()) {
$comment = new Comment;
$comment->body = "test comment 1";
$comment->post_id = $post->id;
if ($comment->save()) {
$transaction->commit();
echo "Transaction Commit Success !!";
}
else {
$transaction->rollBack();
echo "Can't Save \"Comment\" and Transaction Roll Back";
}
}
else {
$transaction->rollBack();
echo "Can't Save \"Post\" and Transaction Roll Back";
}
}
catch(Exception $ex) {
$transaction->rollBack();
echo $ex->getMessage();
}