Welcome Guest, Not a member yet? Register   Sign In
Put Transactions in the Controller or Model
#11

[eluser]Wayne Smallman[/eluser]
Hi!

I like the approach, but what if query is supposed to return something? How does that work with the transaction returning its status?
#12

[eluser]Wayne Smallman[/eluser]
Any thoughts on my question? I've got several insert methods that return their respective IDs back to the application and I'm not sure how to combine the above return logic with that of returning the ID values.
#13

[eluser]Unknown[/eluser]
I am considering adding transactions on begin and end of each request, just like what we did in JavaEE project.
#14

[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.




Theme © iAndrew 2016 - Forum software by © MyBB