Welcome Guest, Not a member yet? Register   Sign In
Active Record Join with Table Alias and Table Prefix
#1

[eluser]Firestorm ZERO[/eluser]
I'm using CI v1.6.1.

Doing this...

Code:
$this->db->select('a.name, b.name');
$this->db->from('dept');
$this->db->join('people AS a', 'dept.supervisor = a.people_id', 'left');
$this->db->join('people AS b', 'dept.head = b.people_id', 'left');

will produce the query...

Code:
SELECT pre_a.name, pre_b.name
FROM (`pre_dept`)
LEFT JOIN `pre_people` AS a ON pre_dept.supervisor = pre_a.people_id
LEFT JOIN `pre_people` AS b ON pre_dept.head = b.people_id

Expected result is...
Code:
SELECT a.name, b.name
FROM (`pre_dept`)
LEFT JOIN `pre_people` AS a ON pre_dept.supervisor = a.people_id
LEFT JOIN `pre_people` AS b ON pre_dept.head = b.people_id

The problem only occurs if you have a table prefix (in the example above it is "pre_").

I just did a search and apparently this problem happened before.
http://codeigniter.com/bug_tracker/bug/1825/
But it says it is resolved. Seems it popped back.

EDIT: Apparently, the 1st join will also have the prefix in the ON statement. But the 2nd join doesn't. I think because if I'm using the same table.


Messages In This Thread
Active Record Join with Table Alias and Table Prefix - by El Forum - 04-09-2008, 07:12 PM
Active Record Join with Table Alias and Table Prefix - by El Forum - 04-10-2008, 08:03 AM
Active Record Join with Table Alias and Table Prefix - by El Forum - 04-10-2008, 08:54 AM
Active Record Join with Table Alias and Table Prefix - by El Forum - 04-10-2008, 09:00 AM
Active Record Join with Table Alias and Table Prefix - by El Forum - 04-15-2008, 02:02 PM
Active Record Join with Table Alias and Table Prefix - by El Forum - 04-15-2008, 09:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB