Active Record $this->db->join bug - 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: Active Record $this->db->join bug (/showthread.php?tid=29539) |
Active Record $this->db->join bug - El Forum - 04-13-2010 [eluser]Shiro[/eluser] Today I found out a bug in Active Record, I am using mysql as my db. CI tread the join first parameter always table id link with another table id E.g Code: $this->db->join('comments', 'comments.id = blogs.id'); in this case, shouldn't be a problem, because CI will auto append ` to the condition become: Quote:JOIN comments ON `comments`.`id` = `blogs`.`id` but today I got a case, which is I don't have any id linking with the table, (For a reason I do that). Code: $this->db->join('marketing', 'marketing.status = "active", 'left'); Quote:JOIN marketing ON `marketing`.`status` = "`active"` which give me database error. now I need to do Code: $this->db->join('marketing', 'marketing.status = marketing.status AND marketing.status = "active", 'left'); Quote:JOIN marketing ON `marketing`.`status` = `marketing`.`status` AND `marketing`.`status` = "active" then this will solve my problem, I think CI should detect first b4 add the `` or add another parameter at the end, allow user escape it #2 Bug 2 I would like to code like this for better viewing, I put the AND condition next line Code: $this->db->join('comments', 'comments.id = blogs.id in this case, it will have another bug. The outcome Quote:JOIN comments ON `comments`.`id` = `blogs`.`idas you can see, it become db error Quote:`id <next line> Active Record $this->db->join bug - El Forum - 04-14-2010 [eluser]WanWizard[/eluser] The two joins you give as an example are not the same. The first one doesn't contain a field to join on, therefore the result will be the product of the two tables (every record joined with every record from the second table). Altough it is a valid query, I don't think AR should consider this syntax as valid. The second one can be easily fixed in the join() method with something like: Code: $cond = str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $cond); Active Record $this->db->join bug - El Forum - 04-14-2010 [eluser]Shiro[/eluser] ya, there are 2 bugs I am mentioned about it. In the first case, for my situation I got one sql string that really don't have a contain field to join, for some reason, I only need the table for the condition purpose. What I suggest is there should be a parameter for it, just in case there are a need for my case, just have an extra parameter to resolve it. thx, for the second part solution. It will be good to mention which line of which file to include it Active Record $this->db->join bug - El Forum - 04-15-2010 [eluser]WanWizard[/eluser] Look in system/database/DB_active_rec.php for the function join(). About 20 lines in there is a preg_match() statement on $cond. Insert the line before that statement... Active Record $this->db->join bug - El Forum - 04-15-2010 [eluser]WanWizard[/eluser] We use this to work around the join condition limitation: Code: $this->db->select('cms_workflow_transitions.*'); Active Record $this->db->join bug - El Forum - 04-26-2010 [eluser]WanWizard[/eluser] SInce my previous post we've come across the need to extend the DB_active_rec.php library, so I decided to rewrite the join() method to get rid of this dirty hack. For those who are interested: Code: /** Active Record $this->db->join bug - El Forum - 02-04-2013 [eluser]parvus[/eluser] this is still a bug after 3 years. thanks for the sensitive dev-team!!! query: Code: $this -> db -> join('predict', "predict.id_predict = portion.id_predict AND event.id_event = {$id_transaction}", 'left'); result: Quote:LEFT JOIN `predict` ON `predict`.`id_predict` = `portion`.`id_predict` AND event.id_event = 5 BUT IT SHOULD BE -> Quote:LEFT JOIN `predict` ON (`predict`.`id_predict` = `portion`.`id_predict` AND `event`.`id_event` = 5) IS THERE ANY PLANS TO FIXING IT IN THE NEXT 25 YEARS ? Active Record $this->db->join bug - El Forum - 02-04-2013 [eluser]Aken[/eluser] Submit an issue on Github, without the attitude, please. Active Record $this->db->join bug - El Forum - 02-04-2013 [eluser]jmadsen[/eluser] [quote author="Aken" date="1360021867"]Submit an issue on Github, without the attitude, please.[/quote] Or better yet, a Pull Request with the tested code. It's open source - you are expected to contribute, not just demand & take Active Record $this->db->join bug - El Forum - 02-04-2013 [eluser]Aken[/eluser] I checked after replying, it's been fixed in 3.0 already. |