natural join with CI Active Record - 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: natural join with CI Active Record (/showthread.php?tid=8412) |
natural join with CI Active Record - El Forum - 05-16-2008 [eluser]inari[/eluser] How can I use natural join with Codeigniter Active Record? Something like: Code: SELECT * C/P: Quote:The NATURAL JOIN joins two tables which contain a column or multiple columns with the same name and data-type. Thanks for any answer natural join with CI Active Record - El Forum - 05-16-2008 [eluser]xwero[/eluser] Code: $this->db->from('employee NATURAL JOIN department'); natural join with CI Active Record - El Forum - 05-16-2008 [eluser]inari[/eluser] How can be used with get_where() method? natural join with CI Active Record - El Forum - 05-16-2008 [eluser]xwero[/eluser] you could try it in the first parameter but i'm not sure it will work. natural join with CI Active Record - El Forum - 09-09-2008 [eluser]roryokane[/eluser] I'm afraid this doesn't work for me. With the code Code: $query = $this->db->select('title, description, length(audio), realname, creationdate, podid')->from('podcasts NATURAL JOIN users')->where('userid', $this->uri->rsegment(4) )->get(); Quote:A Database Error Occurred As you can see, the "JOIN" was quoted and "users" was not. Maybe an update of CodeIgniter stopped this from working. What I'd really like to do, and wish CodeIgniter could do, is say something like Code: $this->db->from('podcasts')->join('users', 'NATURAL') Code: $this->db->from('podcasts')->join('users') I'm having trouble working around this problem without just using $this->db->query(). When I change the middle of the query to Code: ->from('podcasts')->join('users', 'users.userid = podcasts.userid') Quote:A Database Error Occurred, even though I made sure to specify the column names (though stupid MySQL 5.0.41 should be able to realize that the result will be the same after the join). Can anyone help with either of these problems, or tell me how I would officially request or write myself (for the official release) the modification to join()? (I'm not sure if a bug report is appropriate.) natural join with CI Active Record - El Forum - 09-09-2008 [eluser]maesk[/eluser] How about this: Code: $this->db->select('userid, title, description, length(audio), realname, creationdate, podid'); Does this work? natural join with CI Active Record - El Forum - 09-09-2008 [eluser]Sumon[/eluser] [quote author="inari" date="1210996091"]How can I use natural join with Codeigniter Active Record? Code: SELECT customer_id, invoice_id, customer.first_name, customer.last_name Try this Code: $query = $this->db->select('I.customer_id, I.invoice_id, C.customer.first_name, C.customer.last_name') natural join with CI Active Record - El Forum - 09-11-2008 [eluser]roryokane[/eluser] Thanks, maesk. Your code didn't quite work verbatim, but all I needed to do to it is remove the userid in the the the select clause, because I don't need it in the result, and I got an error saying that userid was ambiguous, too. Here is my final code, which works: Code: $this->db->select('title, description, length(audio), realname, creationdate, podid'); It really shouldn't make a difference whether I do it in one statement or many with PHP 5.2.5, so I guess this is a bug in CodeIgniter. natural join with CI Active Record - El Forum - 09-16-2008 [eluser]maesk[/eluser] The select clause, when selecting also the userid from podcasts, probably should have been: Code: $this->db->select('podcasts.userid, title, description, length(audio), realname, creationdate, podid'); instead of Code: $this->db->select('userid, title, description, length(audio), realname, creationdate, podid'); and yes, it should work in one statement, as long as nothing is ambiguous. I couldn't test it but I'm glad you could make it work. |