CodeIgniter Forums
BUG when using JOIN, DBPREFIX and database ALIAS?!?! - 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: BUG when using JOIN, DBPREFIX and database ALIAS?!?! (/showthread.php?tid=21730)



BUG when using JOIN, DBPREFIX and database ALIAS?!?! - El Forum - 08-19-2009

[eluser]Unknown[/eluser]
Hello,

In CI 1.7.1, using a dbprefix (for example "dot_")in ./application/config/database.php, and setting aliases for the tables, the following code is producing a malformed query.

Code:
$this->db->select('d.company, a.activity');
$this->db->join('activities a', 'a.activity_id = d.company_id', 'left');
$this->db->get('directory d', 10);

Generates:

Code:
SELECT `d`.`company`, `a`.`activity` FROM (`dot_directory` d) LEFT JOIN `dot_activities` a ON `a`.`activity_id` = `dot_d`.`company_id` LIMIT 10

Expected:

Code:
SELECT `d`.`company`, `a`.`activity` FROM (`dot_directory` d) LEFT JOIN `dot_activities` a ON `a`.`activity_id` = `d`.`company_id` LIMIT 10

I believe there is a problem with method the _track_aliases in the CI_DB_active_record class, because it is not aware of the fact that table used in method get() has also an alias.

If this was reported before I am sorry, but I searched the forum and did not found this problem reported before.

Thanks!


BUG when using JOIN, DBPREFIX and database ALIAS?!?! - El Forum - 06-17-2011

[eluser]George Petsagourakis[/eluser]
I am so sorry to bring this up from the dead.

I am encountering the exact same issue. Does anyone know how to handle it ?

Edit: $this->db->protect_identifiers() doesn't seem to work in this case at all.


BUG when using JOIN, DBPREFIX and database ALIAS?!?! - El Forum - 06-20-2011

[eluser]danmontgomery[/eluser]
Get rid of the alias? Seems unnecesary in this case


BUG when using JOIN, DBPREFIX and database ALIAS?!?! - El Forum - 06-20-2011

[eluser]George Petsagourakis[/eluser]
[quote author="noctrum" date="1308585161"]Get rid of the alias?[/quote]I'd love to be able to do that. But this is not an option in my case.