php - codeigniter join changing id from one table's id to another
I have this code for an 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 a view without the join statement,$Purchase_req->id
would return the actual purchase request id. In the view with the join,$Purchase_req->id
returns the user id. How can I join the tables together, and still get the purchase request id, instead of it changing to the user.id?
Answer
Solution:
The id you want to achieve is the ambiguous for mysql because the both tables have the id columns therefore when you tries to access the
$Purchase_req->id
it will return the last id column which is from thepurchase_req
table you need to assingn the unique aliases for the same columns in the joined table likeNow when you echo
$Purchase_req->user_id
it will return the user.id