Welcome Guest, Not a member yet? Register   Sign In
[solved] Use of two models and active record
#1

[eluser]kaejiavo[/eluser]
Hi guys,

i just ran into a problem using active records.

In MY_Model i have some CRUD functions e.g.
Code:
function get_all($order_by = NULL, $limit = NULL, $offset = 0) {
if ($order_by !== NULL)
    $this->db->order_by($order_by);

if ($limit !== NULL)
    $this->db->limit($limit, $offset);

$this->db->from($this->table);
$query = $this->db->get();
return $query->result();
}

Model looks like e.g.:
Code:
class Job_detail extends MY_Model {

    function  __construct() {
        parent::__construct();

        $this->table = 'job_details';

        $this->db->select('job_details.*, jobs.name as job_name');
        $this->db->join('jobs', 'job_details.jobs_id = jobs.id');
    }
}
Code:
class Job extends MY_Model {
function  __construct() {
   parent::__construct();
    $this->table = 'jobs';
}
}

I can then use the crud methods of MY_Model with the joined tables.

Now my Problem comes up, when i have to use the two models in one controller, as $this->db->select() and $this->db->join() and their likes seem to work global.
So active record uses the select and join for every model i load from one controller and of course the join does not work properly from table 'jobs' in the Job model.

Could be i am not using this stuff as intended, can anybody help me out with some clues how to do this better or correct?

tia
Marco


Messages In This Thread
[solved] Use of two models and active record - by El Forum - 08-17-2010, 02:23 PM
[solved] Use of two models and active record - by El Forum - 08-18-2010, 12:51 AM
[solved] Use of two models and active record - by El Forum - 08-18-2010, 05:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB