[eluser]Lykos22[/eluser]
Hi, I'd like to ask about a different scenario. Lets say we have these db tables:
Code:
Table: posts
post_id
title
body
-----------------------------
Table: post_images
image_id
post_id
image
Each table corresponds to a model so
post_model for
posts table and
post_image_model for
post_images.
Code:
class Post_Model extends CI_Model {
public function insert(){
// perform insert
return $this->db->insert_id();
}
public function update($post_id){}
public function delete($post_id){}
}
class Post_Image_Model extends CI_Model{
public function upload($post_id){}
public function delete($image_id){}
}
Now if I create a new post how should the transaction be? In this case shouldn't be placed in the controller? Something like this:
Code:
controller_function(){
$this->db->trans_start();
$post_id = $this->post_model->insert();
$this->post_image_model->upload($post_id);
$this->db->trans_complete();
}
Perhaps this is not the best example, but I believe you get the idea.