CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

Active Record Join Multiple conditions

Open bitbucket-import opened this issue 15 years ago • 4 comments

If there is a JOIN with multiple conditions it does not escape everything

For example: {{{

!php

->join('tasks', 'projects.id = tasks.project_id AND tasks.deleted=0', 'left') }}}

does not add the table prefix to the condition tasks.deleted=0

bitbucket-import avatar Aug 19 '11 14:08 bitbucket-import

I have the same issue using postgre driver... please fix this one this a major bug !

kewix avatar Aug 26 '11 16:08 kewix

Tim, thanks for addressing this issue. I think it might need some tweaking, or I am not implementing correctly. Using the above query as an example.

    $this->db->join('tasks', 'projects.id = tasks.project_id AND tasks.deleted=0', 'left')

will create a query string like

    LEFT JOIN `tasks` ON `projects`.`id` = `tasks`.`project_id` AND `tasks`.`deleted`=`0`

Protecting 0 causes a MySQL error. I'm not even sure if this type of case should be automatically handled in the join method. I would of course like it to be, but it might break some other case. For now, I'm just protecting identifiers long hand in the active record query itself, kind of like this post.

http://codeigniter.com/forums/viewthread/119846/#737096

bkirkman avatar Nov 14 '11 17:11 bkirkman

This issue is related to #758 and if properly fixed may replace the solution given on #759. Line 331 should match breaklines and tabs too.

Dentxinho avatar Jan 12 '12 12:01 Dentxinho

This is being handled in #759.

philsturgeon avatar Apr 26 '12 20:04 philsturgeon