php - codeigniter join changing id from one table's id to another -


i have code active record query in codeigniter:

$this->db->join('user', 'user.id = purchase_req.owner_id', 'inner'); $this->db->where('user.employer_id', $user->employer_id); $purchase_req = $this->purchase_req->find(); 

in view without join statement, $purchase_req->id return actual purchase request id. in view join, $purchase_req->id returns user id. how can join tables together, , still purchase request id, instead of changing user.id?

the id want achieve ambiguous mysql because both tables have id columns therefore when tries access $purchase_req->id return last id column purchase_req table need assingn unique aliases same columns in joined table like

$this->db->select('`user`.*,`purchase_req`.*,`user`.id user_id') $this->db->join('user', 'user.id = purchase_req.owner_id', 'inner'); $this->db->where('user.employer_id', $user->employer_id); $purchase_req = $this->purchase_req->find();  

now when echo $purchase_req->user_id return user.id


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -