Welcome Guest, Not a member yet? Register   Sign In
Accesning a model in a model (bad practice?)
#1

[eluser]ennis[/eluser]
Hey guys I am pretty new to mvc and codeignitor.

I do understand the concepts of mvc etc.

I am wokring on a project with another programmer and he is accesing models from inside a model is this bad practice? should what is trying to do be achived through joins in sql or maybe binding data together from 2 different models in the controller?

Any tips or ressource links would be mutch appreciated Smile

Bellow code example where in the client_relation_model the code accesses 2 other models to get some data this just seems very messy too me?

Code:
function findCompanyReferences($company_id){    
        $sql = "SELECT * FROM client_relation WHERE client_id_parent = ?";
        $query  = $this->db->query($sql,array($company_id));

        $CI =& get_instance();
        $CI->load->model('database/clients_model','Clients_model',true);
        $CI->load->model('database/ticket_model','Ticket_model',true);        

        if($query->num_rows > 0){
            
            foreach($query->result() as $row){
                
                $data[] = array($CI->Clients_model->getClientFromID($row->client_id_child),
                                $CI->Ticket_model->getTicketFromClient($row->client_id_child) );

            }
        
            return $data;
        }
        $query->free_result();    
    }}


Messages In This Thread
Accesning a model in a model (bad practice?) - by El Forum - 10-12-2009, 08:32 AM
Accesning a model in a model (bad practice?) - by El Forum - 10-12-2009, 09:12 AM
Accesning a model in a model (bad practice?) - by El Forum - 10-13-2009, 12:50 AM
Accesning a model in a model (bad practice?) - by El Forum - 10-13-2009, 01:40 AM
Accesning a model in a model (bad practice?) - by El Forum - 10-13-2009, 01:47 AM
Accesning a model in a model (bad practice?) - by El Forum - 10-13-2009, 01:58 AM
Accesning a model in a model (bad practice?) - by El Forum - 10-13-2009, 02:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB