CodeIgniter Forums
Potential Bug In ActiveRecord when doing compound join statement - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Potential Bug In ActiveRecord when doing compound join statement (/showthread.php?tid=25178)



Potential Bug In ActiveRecord when doing compound join statement - El Forum - 12-03-2009

[eluser]blasto333[/eluser]
View Database Schema


Code:
$this->db->from('sales');
$this->db->join('sales_items', 'sales.sale_id = sales_items.sale_id');        
$this->db->join('sales_items_taxes', 'sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.item_id = sales_items_taxes.item_id');
$res =  $this->db->get();

echo $this->db->last_query();

produces:
Code:
SELECT * FROM (`phppos_sales`)
JOIN `phppos_sales_items` ON `phppos_sales`.`sale_id` = `phppos_sales_items`.`sale_id`
JOIN `phppos_sales_items_taxes` ON `phppos_sales_items`.`sale_id` = `phppos_sales_items_taxes`.`sale_id`
AND sales_items.item_id = sales_items_taxes.item_id

Notice how the second condition in the 2nd join doesn't have prefixes on the tables. Therefore the query fails. How can I achieve what I am trying to do?